Errors Handling
Overview
In CoverGo's system, any response status code between 200 and 403 (inclusive) should be considered valid.
For error handling, the general flow is as below:
- Check HTTP response status code;
- Check for authentication errors;
- Check for authorization errors;
- Check for data on query or status on mutation.
Checks for HTTP status code
In CoverGo's system, any response status code between 200 and 403 (inclusive) should be considered valid.
Your frontend app should checkout if the reponse status is >= 500 or there is no reponse returned from CoverGo api (eg. becasue of request timeout).
Checks for Authentication Error
Example of authentication error
{
"errors": [
{
"message": "You are not authorized to run this mutation.\ninvalid or expired token",
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"code": "authorization"
}
}
]
}
Checks for Authorization Error
Example of authorization error
{
"data": {
"addTargettedPermission": null
},
"errors": [
{
"message": "demo_uat: You are not authorized to run this. You are missing a 'writeTargettedPermissions' permission for `clientId:AgentPortal`.\n",
"locations": [
{
"line": 34,
"column": 3
}
],
"path": [
"addTargettedPermission"
],
"extensions": {
"code": "authorization"
}
}
]
}
Checks for Quries
In short, as long as the data
field is present, the query can be considered successful.
Example of successful query result
{
"data": {
"cases": {
"list": [
{
"proposals": [
{
"basket": [],
"createdAt": "2021-04-29T00:57:24.258Z",
"createdBy": {
"id": "60810024052f07644d0c3495"
},
"id": "98fe72db-bc18-4ca7-9709-eacc3ae840bf",
"lastModifiedAt": "2021-04-29T00:57:24.258Z",
"lastModifiedBy": {
"id": "60810024052f07644d0c3495"
},
"name": "Demo Proposal",
"notes": null,
"proposalNumber": "NOF8ZO",
"stakeholders": null,
"status": "Created",
"transactions": []
}
]
}
]
}
}
}
Example of unsuccessful query result
In case of failure, errors
will be returned:
{
"errors": [
{
"message": "Object reference not set to an instance of an object.",
"extensions": {
"code": "NULL_REFERENCE"
}
}
]
}
Checks for Mutations
Whether a mutation request is successful or not is indicated by the field status
in result:
Example of successful mutation result
Successful mutation are indicated by {"status": "success"}
. For example:
{
"data": {
"createCompany": {
"createdStatus": {
"id": "661e3924-b2e2-4d07-887e-a35fbe73255d",
"ids": null
},
"errors": null,
"status": "success"
}
}
}
Example of unsuccessful mutation result:
Unsuccessful mutation are indicated by {"status": "failure"}
. For example:
{
"data": {
"inviteEntityToLogin": {
"createdStatus": null,
"status": "failure",
"errors": [
"DuplicateUserName|Username '[email protected]' is already taken."
]
}
}
}