Note that there are some explanatory texts on larger screens.

plurals
  1. POMappingProvider's errorMapping always fails with: Could not find an object mapping for keyPath: ''
    primarykey
    data
    text
    <p>I am experiencing difficulties mapping my API's errors. I am loading requests using blocks like this:</p> <pre><code>[self.objectManager loadObjectsAtResourcePath:resourcePath usingBlock:^(RKObjectLoader *loader) { loader.onDidLoadObjects = ^(NSArray *objects) { // ... }; loader.onDidFailLoadWithError = ^(NSError *error) { // ... }; loader.onDidFailWithError = ^(NSError *error) { // ... }; }]; </code></pre> <p>On the server side if, eg, I attempt to authenticate a user with wrong username/password, my API returns and error with the following format:</p> <pre><code>{ "error": {"code":"401", "message":"Wrong username etc. etc."} } </code></pre> <p>In the <a href="https://github.com/RestKit/RestKit/wiki/Object-mapping" rel="nofollow noreferrer">object mapping docs</a> I have found the following:</p> <blockquote> <h3>RKErrorMessage</h3> <p>A simple class providing for the mapping of server-side error messages back to NSError objects [...] When an RKObjectManager is initialized, object mappings from the "error" and "errors" keyPaths to instances of RKErrorMessage are registered with the mapping provider. This provides out of the box mapping support for simple error messages. [...]</p> </blockquote> <p>Which I interpret as the object loader automatically will map any "error" og "errors" keyPath's accordingly, and didFailWithError: (or block) will get called. This is not the situation, though. I get this error every time an error response is loaded from the API: </p> <blockquote> <p>Adding mapping error: Could not find an object mapping for keyPath: ''</p> </blockquote> <p>I have tried solutions from <a href="https://stackoverflow.com/questions/10851239/how-do-i-setup-restkit-0-10-0-to-recognize-error-and-errors-messages">this questions</a> and <a href="https://stackoverflow.com/questions/9841203/restkit-json-error-response-msg-from-server">this question</a>, but the result is the same.</p> <p>I know the json is loaded from my API, I have tracked that in the debugger. Also, if I create an RKObjectMapping and maps it to the "error" keyPath, onDidLoadObjects block is fired with an Error object, but this is not what I intend to do.</p> <p>Long story short, my goal is that make RestKit fire an onDidFailWithError block whenever an "error" keyPath is returned by my API.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload