2022-09-12 21:43:26 +12:00
|
|
|
import { HTTPError } from "./http"
|
|
|
|
import { UsageLimitError, FeatureDisabledError } from "./licensing"
|
|
|
|
import * as licensing from "./licensing"
|
2022-03-05 02:42:50 +13:00
|
|
|
|
|
|
|
const codes = {
|
|
|
|
...licensing.codes,
|
|
|
|
}
|
|
|
|
|
2022-04-08 12:28:22 +12:00
|
|
|
const types = [licensing.type]
|
2022-03-05 02:42:50 +13:00
|
|
|
|
2022-03-17 06:29:47 +13:00
|
|
|
const context = {
|
|
|
|
...licensing.context,
|
|
|
|
}
|
|
|
|
|
2022-09-12 21:43:26 +12:00
|
|
|
const getPublicError = (err: any) => {
|
2022-03-17 06:29:47 +13:00
|
|
|
let error
|
|
|
|
if (err.code || err.type) {
|
|
|
|
// add generic error information
|
|
|
|
error = {
|
|
|
|
code: err.code,
|
|
|
|
type: err.type,
|
|
|
|
}
|
|
|
|
|
2022-03-20 14:13:54 +13:00
|
|
|
if (err.code && context[err.code]) {
|
2022-03-17 06:29:47 +13:00
|
|
|
error = {
|
|
|
|
...error,
|
|
|
|
// get any additional context from this error
|
|
|
|
...context[err.code](err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error
|
|
|
|
}
|
|
|
|
|
2022-09-12 21:43:26 +12:00
|
|
|
const pkg = {
|
2022-03-05 02:42:50 +13:00
|
|
|
codes,
|
|
|
|
types,
|
2022-04-08 12:28:22 +12:00
|
|
|
errors: {
|
2022-09-12 21:43:26 +12:00
|
|
|
UsageLimitError,
|
|
|
|
FeatureDisabledError,
|
|
|
|
HTTPError,
|
2022-04-08 12:28:22 +12:00
|
|
|
},
|
2022-03-17 06:29:47 +13:00
|
|
|
getPublicError,
|
2022-03-05 02:42:50 +13:00
|
|
|
}
|
2022-09-12 21:43:26 +12:00
|
|
|
|
|
|
|
export = pkg
|