Error Handling

This guide will show you how to handle errors on Lens.


Lens tools categorize errors as either failures or exceptions:

  • Failure: A known issue directly related to business logic prevents the task from completing successfully. These scenarios are anticipated and managed within the application.

  • Exception: An unexpected issue arises, such as incorrect usage, invariant errors, or external/system malfunctions, which are not tied to business logic.

The Lens API embraces this distinction by modeling failures as part of the response payload. For instance, when a mutation fails, the response provides a structured outcome that specifies the nature of the failure:

Mutation
mutation {  authenticate(request: { id: "<challenge.id>", signature: "<signature>" }) {    ... on AuthenticationTokens {      accessToken      refreshToken      idToken    }
    ... on WrongSignerError {      reason    }
    ... on ExpiredChallengeError {      reason    }
    ... on ForbiddenError {      reason    }  }}

In contrast, exceptions are represented as GraphQL Errors and occur in cases where an unexpected issue, such as a validation error, disrupts the query or mutation execution.

Error Response
{  "errors": [    {      "message": "Validation error",      "locations": [        {          "line": 2,          "column": 3        }      ],      "path": ["authenticate"],      "extensions": {        "code": "INTERNAL_SERVER_ERROR"      }    }  ],  "data": {    "authenticate": null  }}