Constructor
new ErrorCase(definition, optionsopt)
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
definition |
ErrorCaseDefinition | The case definition settings. |
||
options |
ErrorCaseOptions |
<optional> |
{}
|
The options to customize how the class behaves. |
Throws:
-
-
If the definition is missing the
name
, thecondition
or themessage
. - Type
- Error
-
-
-
If the definition
message
is not a string nor a function. - Type
- TypeError
-
-
-
If the definition
condition
is not a RegExp nor a string. - Type
- TypeError
-
-
-
If the definition includes
parsers
and it's not an object. - Type
- TypeError
-
-
-
If a parser is not an object, a function or an instance of
CaseParser
. - Type
- TypeError
-
-
-
If the definition includes
parse
and it's not anarray
nor an object. - Type
- TypeError
-
-
-
If the definition includes
parse
and an item is not anarray
, a function or an object. - Type
- TypeError
-
Members
name :string
- Source:
The case name.
Type:
Methods
parse(errorMessage, scopesopt, contextopt, nullable) → (nullable) {FormattedError}
- Source:
Validates an error message against the case condition and if it matches, it parses it in order to return a formatted error.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
errorMessage |
string | The error message to validate and, possibly, parse. |
||
scopes |
Array.<Scope> |
<optional> |
[]
|
A list of scopes from where the case can try to find reusable parsers. |
context |
Object |
<optional> <nullable> |
null
|
Custom context information about the error that can be sent to the formatted error. |
Throws:
-
-
If the condition matches, parameters are extracted as named groups but the case's
parse
instructions were defined as an array. - Type
- Error
-
-
-
If the condition matches, parameters are extracted as a list but the case's
parse
instructions were defined as an object. - Type
- Error
-
-
-
If the condition matches, one of the parsers the case wants to use is suppoused to be on one of the scopes but it can't be found.
- Type
- Error
-
-
-
If the condition has a mix of named and unnamed groups.
- Type
- Error
-
Returns:
If the condition doesn't match, it will return null
.
- Type
- FormattedError