JWPlayer Errors
This repo contains a standardized, numerical set of errors used by JWPlayer and its plugins.
Installation
npm i -D jwplayer-errors
API Docs
Usage
Importing
Each module is a named export:
build, Category, Code, Severity, Data
You can import them all with the following syntax:
import * as JWError from 'jwplayer-errors;'
Or individually:
import Category from 'jwplayer-errors;'
Building errors
Errors are composed of a Category
, Code
, Severity
, and an optional Data
object, which are passed into the build
function with the following signature:
build(category, code, severity, data)
The build function uses these arguments to generate a standardized error message, which it returns along with the numerical values (while omitting the data
object):
{
category,
code,
severity,
message
}
Important!: The data
argument must be created with a factory function from the JWError.Data
module. Data arguments are expected to conform to a certain structure.
Example
import * as JWError from `jwplayer-errors`;
const networkErrorData = JWError.Data.Network('https://jwplayer.com', 404, 'Not found');
const error = JWError.build(
JWError.Category.NETWORK,
JWError.Code.BAD_HTTP_STATUS,
JWError.Severity.FATAL,
networkErrorData
);