unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
87 lines • 2.56 kB
JavaScript
import { v4 as uuidV4 } from 'uuid';
export const UnleashApiErrorTypes = [
'ContentTypeError',
'ConflictError',
'DisabledError',
'FeatureHasTagError',
'IncompatibleProjectError',
'InvalidOperationError',
'InvalidTokenError',
'NameExistsError',
'NoAccessError',
'NotFoundError',
'NotImplementedError',
'OperationDeniedError',
'PasswordMismatch',
'PasswordUndefinedError',
'ProjectWithoutOwnerError',
'RoleInUseError',
'UnknownError',
'UsedTokenError',
'BadDataError',
'ValidationError',
'AuthenticationRequired',
'UnauthorizedError',
'PermissionError',
'InvalidTokenError',
'OwaspValidationError',
'ForbiddenError',
'ExceedsLimitError',
'PasswordPreviouslyUsedError',
'RateLimitError',
// server errors; not the end user's fault
'InternalError',
];
export class UnleashError extends Error {
constructor(message, name) {
super();
this.id = uuidV4();
this.name = name || this.constructor.name;
super.message = message;
}
help() {
return `Get help for id ${this.id}`;
}
toJSON() {
return {
id: this.id,
name: this.name,
message: this.message,
details: [{ message: this.message }],
};
}
toString() {
return `${this.name}: ${this.message}`;
}
}
export class GenericUnleashError extends UnleashError {
constructor({ name, message, statusCode, }) {
super(message, name);
this.statusCode = statusCode;
}
}
export const apiErrorSchema = {
$id: '#/components/schemas/apiError',
type: 'object',
required: ['id', 'name', 'message'],
description: 'An Unleash API error. Contains information about what went wrong.',
properties: {
name: {
type: 'string',
description: 'The kind of error that occurred. Meant for machine consumption.',
example: 'ValidationError',
},
id: {
type: 'string',
description: 'A unique identifier for this error instance. Can be used to search logs etc.',
example: '0b84c7fd-5278-4087-832d-0b502c7929b3',
},
message: {
type: 'string',
description: 'A human-readable explanation of what went wrong.',
example: "We couldn't find an addon provider with the name that you are trying to add ('bogus-addon')",
},
},
components: {},
};
//# sourceMappingURL=unleash-error.js.map