Graphql error revamp
December 28th, 2020
We have revamped the Graphql errors in Graphql standards, returning 200 response codes with errors as messages in response. 

Old error codes:
Currently the restructuring of graphql errors were done for the following error types:

In build errors:

  • ActiveRecord::RecordNotFound 

  • ActiveRecord::RecordInvalid

  • ActiveRecord::StatementInvalid

  • ActiveRecord::RecordNotUnique

Custom errors:

  • EntityNotFound 

  • InvalidRecord

All internal server errors(status code - 500) are also rescued and presented to the frontend. This particular response will include the rollbar id for the error to easily debug it.

The above-mentioned errors do go through Graphql API endpoints and are being rescued. There are two other scenarios where we check a few validations before the API endpoint is triggered. These errors are not rescued now and require infrastructure change which will also impact Rest endpoints. The following are those scenarios:

  • Invalid Account Type - This is used to determine which user can access which platform. Example scenario. YOP users should not be able to access EXPA.

  • Invalid Access Token - When the provided access token is invalid.

To fix the above two scenarios we will need to have an infrastructure update to Graphqh. We can take this forward in the future.

Note: The error codes which will remain the same are 401 and 406.

Sample Request & Response:

1. ActiveRecord::RecordNotFound:

Request:
query getApplicationQuery {
 getApplication(id: 628134) {
   id
 }
}

Response:
Status: 200
{
  "data": {
    "getApplication": null
  },
  "errors": [
    {
      "message": "Requested record not found.",
      "locations": [
        {
          "line": 2,
          "column": 2
        }
      ],
      "path": [
        "getApplication"
      ],
      "extensions": {
        "code": "record_not_found"
      }
    }
  ]
}

2. ActiveRecord::RecordInvalid

Request:
mutation{
  createOpportunity(opportunity: {home_lc_id: 630,   branch_id: 1,  programme_id: 9}){
    id
  }
}

Response:
Status: 200
{
  "data": {
    "createOpportunity": null
  },
  "errors": [
    {
      "message": "Title can't be blank",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "createOpportunity"
      ],
      "extensions": {
        "code": "unprocessable_entity",
        "sub_code": "record_invalid",
        "message": "Title can't be blank"
      }
    }
  ]
}

3.EntityNotFound

Request:
query{
  checkPersonPresent(email: "testinng@commutatus.com"){
    id
  }
}

Response:
Status: 200
{
  "data": {
    "checkPersonPresent": null
  },
  "errors": [
    {
      "message": "Requested entity not found.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "checkPersonPresent"
      ],
      "extensions": {
        "code": "unprocessable_entity",
        "sub_code": "entity_not_found",
        "message": "Requested entity not found."
      }
    }
  ]
}

4.InvalidRecord

Request:
mutation{
  updateCommittee(id: 1558, committee: {default_project_fee_cents: 4500, project_fee_limit_cents: 100}){
    id
   
    default_currency{
      id
    }
  }
}

Response:
Status: 200
{
  "data": {
    "updateCommittee": null
  },
  "errors": [
    {
      "message": "project_fee_limit value should not be lesser than default_project_fee value.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "updateCommittee"
      ],
      "extensions": {
        "code": "unprocessable_entity",
        "sub_code": "invalid_record",
        "message": "project_fee_limit value should not be lesser than default_project_fee value."
      }
    }
  ]
}



X
Crafted by