Skip to main content

@ones-op/node-error

Require​

ONES
v3.13.31+

Install​

Enter the /backend directory of the plug-in project, and execute the following command to install dependencies:

npm i @ones-op/node-error

API​

clientError​

throw client error

Params​

ParamDescriptionTypeRequiredDefault
reasonwrong reasonstringyes-

Example​

import { clientError } from '@ones-op/node-error'

export async function testClientError() {
throw clientError('test client error')
}

serverError​

Throw server error error

Params​

ParamDescriptionTypeRequiredDefault
reasonwrong reasonstring是-

Example​

import { serverError } from '@ones-op/node-error'

export async function testServerError() {
throw serverError('test server error')
}

sdkErrorToPluginError​

The error of the sdk package is converted into a plug-in registration interface error

Params​

ParamDescriptionTypeRequiredDefault
abilityErrorThe wrong type of an sdk packageanyYes-

Returns​

ParamDescriptionType
resultPlugin error corresponding to sdk package errorPluginError

Example​

import { sdkErrorToPluginError } from '@ones-op/node-error'

export async function testSdkErrorToPluginError() {
const e = new AbilityError('error', 'errrcode', 500, 'reason')
e.statusCode = 500
e.reason = 'reason'
e.level = 'level'
e.errcode = 'errcode'
const pluginError = sdkErrorToPluginError(e)
throw pluginError
}

Type​

PluginError​

ParamDescriptionType
typeerror levelPluginErrorTypeEnum
reasonwrong reasonstring
statusCodeCorresponding http status codestring
errcodeerror codestring

Enum​

PluginErrorTypeEnum​

pluginError error level

EnumDescription
PluginErrorTypeEnum.errorerror level
PluginErrorTypeEnum.warningwarning level

CommonReason​

pluginError common error reason

EnumText
CommonReason.RequestTimeOutRequest time out.
CommonReason.ServiceUnresponsiveService unresponsive.
CommonReason.ServiceIsNotAvailableService is not available.
CommonReason.InvalidParameterInvalid parameter.
CommonReason.NetworkErrorNetwork error.