RESTframework
RESTframework copied to clipboard
Exception handling
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)
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 } }]
I'll update the README file with some examples and close this issue when I do...
Great, Thank you. The wrapper looks promising :)
Just want to confirm, it's working! How about additional headers? I want pass my custom user-agent http header is there anyway?
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.