Error responses that use this error template feature the following fields:

  • code
  • message
  1. Create a file named error-template.vtl with the following contents:
    #set ($code = "UNEXPECTED_ERROR")
    #if($status == 403)
      #set ($code = "ACCESS_FAILED")
  2. Add the error template to the configuration, as follows:
    dsconfig create-error-template \
      --template-name "Custom Error Template" \
      --set "velocity-template<error-template.vtl"
  3. Assign the error template to the Gateway API Endpoint, as follows:
    dsconfig set-gateway-api-endpoint-prop \
      --endpoint-name "Test API" \
      --set "error-template:Custom Error Template"

    The error template is used whenever the gateway generates an error in response to a request.

    A policy deny results in a response like the following example:
    HTTP/1.1 403 Forbidden
    Content-Length: 57
    Content-Type: application/json;charset=utf-8
    Correlation-Id: e7c8fb82-f43e-4678-b7ff-ae8252411513
    Date: Wed, 27 Feb 2019 05:54:50 GMT
    Request-Id: 56
      "code": "ACCESS_FAILED",
      "message": "Access Denied"