@rtorcato/cf-common
Classes
CloudflareError
Defined in: index.ts:14
An error that carries an HTTP status, for Workers that turn thrown errors
into Responses.
expose marks whether message is safe to send to the client: it defaults
to true for 4xx (the caller's fault, tell them why) and false for 5xx
(our fault — don't leak internals).
Example
throw new CloudflareError('Session not found', { status: 404 })
Extends
Error
Constructors
Constructor
new CloudflareError(
message,options?):CloudflareError
Defined in: index.ts:21
Parameters
message
string
options?
status?
number
expose?
boolean
code?
string
cause?
unknown
Returns
Overrides
Error.constructor
Properties
name
readonlyname:"CloudflareError"='CloudflareError'
Defined in: index.ts:15
Overrides
Error.name
status
readonlystatus:number
Defined in: index.ts:16
expose
readonlyexpose:boolean
Defined in: index.ts:17
code?
readonlyoptionalcode?:string
Defined in: index.ts:19
Optional machine-readable code (e.g. KV_PARSE_FAILED) for branching on a specific failure.
Functions
isCloudflareError()
isCloudflareError(
error):error is CloudflareError
Defined in: index.ts:33
Type guard for CloudflareError.
Parameters
error
unknown
Returns
error is CloudflareError
toCloudflareError()
toCloudflareError(
error,status?):CloudflareError
Defined in: index.ts:42
Coerce any thrown value into a CloudflareError, passing an existing
one through unchanged. Reuses js-common's getErrorMessage for the message
and defaults to a non-exposed 500.
Parameters
error
unknown
status?
number = 500