Looking for the Prisma documentation? You can find it here

Error Handling for Functions

Last updated a day ago Edit this page

#Overview

Functions follow a unified concept for error handling.

To return an error from a webhook function, it's important to respond with status code 200!

#Provoking an error

By returning an object that contains an error property, you can populate errors from your functions. If your function is called as part of the request pipeline, further processing of the incoming request is aborted.

#Returning error messages

To return an error message, returns an object with the key error that is a String:

1
2
3
4
5
export default event => {
  return {
    error: "Invalid email!"
  }
}

Then the response to the request that resulted in that error will include the supplied string and a generic error code is included as GraphQL error:

1
2
3
4
5
6
7
8
9
10
{
  "data": null,
  "errors": [
    {
      "code": 5001,
      "message": "Function execution error: 'Invalid email!'",
      "functionError": "Invalid email!"
    }
  ]
}

#Returning error objects

For debugging or user-facing errors or other situations where more custom behaviour is needed you can return a JSON object instead of a string as the error property in your function:

1
2
3
4
5
6
7
8
9
10
export default event => {
  return {
    error: {
      code: 42,
      message: "Invalid email!",
      debugMessage: "We should add validation in the frontend as well!",
      userFacingMessage: "Please supply a valid email address!"
    }
  }
}

Then the response to the request that resulted in that error will include the error JSON object as well as a generic error code as a GraphQL error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
  "data": null,
  "errors": [
    {
      "code": 5002,
      "message": "Function execution error",
      "functionError": {
        "code": 42,
        "message": "Invalid email!",
        "debugMessage": "We should add validation in the frontend as well!",
        "userFacingMessage": "Please supply a valid email address!"
      }
    }
  ]
}

#Unexpected errors

In case the function failed in an unexpected way, we return a generic error message and an executionId. Have a look at your function to fix this problem or check the function logs using graphcool logs.

1
2
3
4
5
6
7
8
9
{
  "data": null,
  "errors": [
    {
      "code": 5000,
      "message": "A function returned an unhandled error. Please check the logs for executionId 'cj27leckw31to0153whdva5b2'"
    }
  ]
}

Was this page helpful?