predictype

predictype v0.13.0


predictype / predicates/errors / errorMessagePattern

Function: errorMessagePattern()

errorMessagePattern(source, oper, pattern): boolean

Defined in: predicates/errors/errorMessagePattern.ts:25

Evaluates an error message against a pattern operation (matches or not matches a RegExp) using the specified operation.

Parameters

source

Error

The Error whose message will be tested.

oper

ErrorMessagePatternOper

The pattern operation to perform (e.g. ‘matches’, ‘not_matches’).

pattern

RegExp

The RegExp to test against.

Returns

boolean

True if the operation matches, false otherwise.

Throws

If the operation is not recognized.

Example

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

errorMessagePattern(err, 'matches', /timeout$/); // true
errorMessagePattern(err, 'not_matches', /syntax/i); // true

Remarks

Supported Operators: