code: function toCustomOrDefaultErrorResponse(error, event, context) {
    try {
      const handler = context && context.handler;
      const toErrorResponse = handler && handler.toErrorResponse;
      return typeof toErrorResponse === 'function' ?
        toErrorResponse(error, event, context) || toDefaultErrorResponse(error) :
        toDefaultErrorResponse(error);
    } catch (err) {
      log(context, LogLevel.ERROR, err);
      // fallback to default function if given function fails
      return toDefaultErrorResponse(error);
    }
  }
docs: Resolves the error response to be returned for the given AppError and event, using the configured `toErrorResponse`
  function (if any); otherwise using the `toDefaultErrorResponse` function.
  @param {AppError} error - the error with which your Lambda was failed
  @param {Object} event - the AWS event passed to your handler
  @param {StandardHandlerContext} context - the context being used
  @param {ToErrorResponse|undefined} [context.handler.toErrorResponse] - an optional function to be used by an AWS
  Lambda `handler` function to convert an AppError into an appropriate error response object
  @return {Object} the error response (to be subsequently stringified & returned)