Exceptions.RequestError(message, dataopt, codeopt)

Thrown to shortcut request handling and return an HTTP error.

new RequestError(message, dataopt, codeopt)

Parameters:
Name Type Attributes Default Description
message String The human-readable error message to send back in the JSON response data (in the "error" key).
data Object <optional>
{} Optional additional JSON data to send back in the error response body.
code Number <optional>
400 The HTTP status code to respond with; defaults to STATUS
See:
  • RequestDone

Members

static respSchema

Schema to use on returned data

respData

Data to return to the caller

Methods

forceSentry() → {RequestError}

Force this client error (status < 500) to be reported to Sentry. By default a RequestError below 500 is not reported: it is an expected outcome deliberately thrown by the app (access denied, bad input, etc.) whose reports would only consume the Sentry quota. (Crashes and errors not thrown through these exception classes are always reported.) The HTTP response and logs always include the error either way. Returns `this`, so it can be chained at the throw site: throw new BadRequestException('suspicious input').forceSentry()
Returns:
RequestError - this

rateLimitSentry(windowMsopt) → {RequestError}

Mark this error for rate-limited Sentry reporting. Useful when a known dependency outage causes the same error to fire repeatedly -- Cloud Tasks retries, etc. The HTTP response and logs are unaffected; only the Sentry report is throttled so the error budget doesn't get exhausted during the outage. Returns `this`, so it can be chained at the throw site: throw new RequestError('failed to send email', { err }, 550) .rateLimitSentry() Rate-limit keying follows the Sentry fingerprint we'd have used anyway (so Sentry grouping and our suppression agree on what "the same error" is).
Parameters:
Name Type Attributes Default Description
windowMs Number <optional>
300000 rate-limit window in ms; at most one Sentry report is sent per window per key (default 5 minutes).
Returns:
RequestError - this