New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support errorModelClass for HTTP 2XX. #60
Comments
For that case my recommendation is to subclass |
I believe I am having a similar issue. My response JSON for errors has a different path than that of a successful response. I cannot figure out how to get Overcoat to use my Error class. Its like I need to register another ServerResponse class for error responses. SPCAPIError is a subclass of OVCResponse. // I have set this up. JSON Returned from our API: On Error:
On Success:
|
Hi @yuzaken. Which HTTP status codes is your service returning on error? |
In this example, 403, along with the JSON content outlined above. To be precise: HTTP/1.0 403 Forbidden {"error":{"code":403,"title":"Forbidden","message":"The selected email is invalid.","recoverySuggestion":"Try the request again"}} The raw details of the response looks like (Apologies for the lack of formatting)... :) Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo=0x7f9c83c3a100 {NSLocalizedDescription=Request failed: forbidden (403), NSUnderlyingError=0x7f9c83c636d0 "Request failed: unacceptable content-type: text/html", NSErrorFailingURLKey=https://staging-app.snapc.am/user/auth, OVCResponse=<OVCResponse: 0x7f9c83c5b9d0> { |
Then you could create a model for your error response, with the right mappings for the expected JSON: @interface SPCAPIError : MTLModel<MTLJSONSerializing>
@property (copy, nonatomic, readonly) NSNumber *code;
@property (copy, nonatomic, readonly) NSString *message;
@property (copy, nonatomic, readonly) NSString *title;
@property (copy, nonatomic, readonly) NSString *recoverySuggestion;
@end
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"code": @"error.code",
@"message": @"error.message",
@"title": @"error.title",
@"recoverySuggestion": @"error.recoverySuggestion"
};
} And set it up in your client subclass by overriding + (Class)errorModelClass {
return [SPCAPIError class];
} Let me know if that works for you. |
I have done as you described. But the problem I am seeing is that: OVCModelResponseSerializer.m:74 - OVCModelResponseSerializer.m:101 pass in a nil JSONObject into: So there is no way for the error response can work with a nil JSONObject as far as I can see. |
@yuzaken I got the same issue when trying the example(TwitterTimeline) too. Error Log here: https://gist.github.com/chakming/6e962ec1450bbd52efdc |
I'm working with some web services that are setup to keep HTTP response codes limited to transport and leave the client response as part of the body. As such, I may get an HTTP 200 but with an error model. I'm not sure the best place to inject such support. Perhaps in OVCModelResponseSerializer in the event there's an error OR a serializationError?
The text was updated successfully, but these errors were encountered: