predictype

predictype v0.13.0


predictype / predicates/errors / errorMessage

Function: errorMessage()

errorMessage(source, oper, target): boolean

Defined in: predicates/errors/errorMessage.ts:27

Checks the message of an Error using the specified operation.

Parameters

source

Error

The Error to check.

oper

ErrorMessageOper

The message operation to perform (e.g. ‘equals’, ‘includes’).

target

string

The string to compare the error message against.

Returns

boolean

True if the message check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const err = new Error('Network timeout');

errorMessage(err, 'includes', 'timeout'); // true
errorMessage(err, 'starts_with', 'Network'); // true

Remarks

Supported Operators: