JsonApiClient / json_api_client

Build client libraries compliant with specification defined by jsonapi.org
MIT License
361 stars 186 forks source link

Accessing application error code from the resource #388

Open sebasjimenez10 opened 3 years ago

sebasjimenez10 commented 3 years ago

tl;dr

Similar to https://github.com/JsonApiClient/json_api_client/issues/368 I found myself needing to extract the application error code from a response with errors.

I was able to get it via the last_result_set attribute on the resource instance. However, this does seem as an undesired way to grab the application error code.

Context

For context, given a response like this one:

{
  "errors": [
    {
      "title": "Name Validation Error",
      "detail": "name - can't be used more than once per family member",
      "code": "1000",
      "source": {
        "pointer": "/data/attributes/name"
      },
      "status": "422"
    }
  ]
}

I would like to extract the application error code (see the "code: 1000" piece) from the resource errors in somewhat a similar way to:

family_member.errors.code
# or
family_member.errors.application_codes
# or
family_member.errors.attrs['codes']

This would allow clients to map application error codes better.

Can I please get some guidance or feedback here!? Thanks in advance! I would love to contribute as well if this is something that makes sense for the future of the project.

sobakasu commented 2 years ago

this is similar to https://github.com/JsonApiClient/json_api_client/issues/195