RESTframework icon indicating copy to clipboard operation
RESTframework copied to clipboard

Exception handling

Open t0lkman opened this issue 12 years ago • 5 comments

Can you post some examples how to handle exceptions?

let say you do [RFService execRequest:r completion:^(RFResponse *response) {

but server is not available or the document is not found (404)

t0lkman avatar May 07 '12 23:05 t0lkman

You'll just need to check RFResponse's error property:

/*!

  • @property error
  • @abstract This propery will hold NSError if one occurs during request. NULL if there's no error / @property (nonatomic, readonly, retain) NSError error;

This property will contain the NSError in case something goes wrong. For HTTP errors you can also check the httpCode property of RFResponse:

/*!

  • @property httpCode
  • @abstract HTTP code RESTful service returned (e.g. 200, 404, 400, 500 etc...) */ @property int httpCode;

basically you'd do something like

[RFService execRequest:r completion:^(RFResponse *response) { if (response.error) { //there's an error, handle it return; } if (response.httpCode == 200) { //all good } else { //check your status } }]

ivasic avatar May 08 '12 16:05 ivasic

I'll update the README file with some examples and close this issue when I do...

ivasic avatar May 08 '12 16:05 ivasic

Great, Thank you. The wrapper looks promising :)

t0lkman avatar May 08 '12 16:05 t0lkman

Just want to confirm, it's working! How about additional headers? I want pass my custom user-agent http header is there anyway?

t0lkman avatar May 09 '12 02:05 t0lkman

Yeah, just use additionalHTTPHeaders property of RFRequest.

/*!

  • @property additionalHTTPHeaders
  • @abstract Additional HTTP headers in form of key/value dictionary to include with the HTTP request / @property (nonatomic, retain) NSDictionary additionalHTTPHeaders;

Just add key-value pairs to a NSDictionary and assign to this property.

ivasic avatar May 09 '12 07:05 ivasic