evermeer / AlamofireJsonToObjects

An Alamofire extension which converts JSON response data into swift objects using EVReflection
Other
161 stars 28 forks source link

Is not key value coding-compliant for the key __response_statusCode? #37

Closed Dbigshooter closed 7 years ago

Dbigshooter commented 7 years ago

Just updated EVReflection and this lib, and all my classes says this, what is that?


WARNING: The class 'ClassName' is not key value coding-compliant for the key '__response_statusCode'
 There is no support for optional type, array of optionals or enum properties.
As a workaround you can implement the function 'setValue forUndefinedKey' for this. See the unit tests for more information
evermeer commented 7 years ago

The key __response_statusCode will be added when the http status code is 200 or higher. AlamofireJsonToObjects will still try to parse the object because some systems will also return an error object in json format.

You can choose to include the error fields inside your object (or in a base class) or you could use the getSpecificType function to get an error object.

The question is why you are getting a status code >= 200

Dbigshooter commented 7 years ago

But it shouldn't be a problem to get a 200 status code? I see no errors with me calls what so ever?

evermeer commented 7 years ago

You are right. It should be > 200. I have changed the code that if its 200 you won't get __response_statusCode

Dbigshooter commented 7 years ago

I still see the same outcome? I get status code 200 on all my requests. Have you pushed it to cocoapods?

evermeer commented 7 years ago

2.3.1 is the latest release both in Cocoapods as in GitHub.

As a test I just downloaded the latest release from https://github.com/evermeer/AlamofireJsonToObjects/releases

When I look at AlamofireJsonToObjects.swif I see this check twice: if response?.statusCode ?? 0 > 200 {

So If you do have that update, it should only get the __response_statusCode if the statusCode is above 200

So do you have the same code? If not, then why is it not updated to the latest version? If you do have the code, then your status code should be above 200. Or am I missing something else?

Dbigshooter commented 7 years ago

I imagine you should do the check on >= 300, since status codes in the 200 range is just fine. 201 = created, 202 = accepted and so on.

When I updated my repo I just got version 2.2.0 from cocoapods? Does the new version require the beta of new release of cocoapods?

evermeer commented 7 years ago

I don't know why you would get the old version... Could it be because of the supported OS version? Since Swift 3 it should be iOS 8 and up. I will change the status check to >= 300

Dbigshooter commented 7 years ago

Wow, my bad. I had the library in the pod set to a specific branch, my apologies.

evermeer commented 7 years ago

no worries 😎

evermeer commented 7 years ago

I just pushed a new version (2.4.0) with better support for handling HTTP error statuses.

It's explained in the readme. For a unit test demonstrating this, see: https://github.com/evermeer/AlamofireJsonToObjects/blob/master/AlamofireJsonToObjectsTests/AlamofireJsonToObjectsTests.swift#L81