aronbalog / Vox

Swift JSON:API client framework
http://jsonapi.org
MIT License
45 stars 19 forks source link

Context handling error response as unknown incorrectly. #32

Open markturnip opened 4 years ago

markturnip commented 4 years ago

My response payload contains the following error:

{
    "errors": {
        "detail": {
            "auth": [
                "invalid password"
            ]
        }
    }
}

However Vox will always respond with JSONAPIError.serialization due to not casting the error array correctly: https://github.com/aronbalog/Vox/blob/master/Vox/Core/Class/Context.swift#L42

(lldb) po dictionary["errors"] as? NSArray
nil

(lldb) po dictionary["errors"] as? NSMutableArray
nil

(lldb) po type(of: dictionary["errors"])
Swift.Optional<Any>

(lldb) po dictionary["errors"]
▿ Optional<Any>
  ▿ some : 1 element
    ▿ 0 : 2 elements
      - key : detail
      ▿ value : 1 element
        ▿ 0 : 2 elements
          - key : auth
          ▿ value : 1 element
            - 0 : invalid email or password
markturnip commented 4 years ago

ah this may well be due to the fact the response is a dictionary rather than a array!