bifocal/node_modules/@tryghost/errors/es/errors.js

311 lines
8.2 KiB
JavaScript

import { GhostError } from "./GhostError";
const mergeOptions = (options, defaults) => {
const result = { ...defaults };
Object.keys(options).forEach((key) => {
if (options[key] !== void 0) {
result[key] = options[key];
}
});
return result;
};
class InternalServerError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 500,
level: "critical",
errorType: "InternalServerError",
message: "The server has encountered an error."
}));
}
}
class IncorrectUsageError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 400,
level: "critical",
errorType: "IncorrectUsageError",
message: "We detected a misuse. Please read the stack trace."
}));
}
}
class NotFoundError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 404,
errorType: "NotFoundError",
message: "Resource could not be found.",
hideStack: true
}));
}
}
class BadRequestError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 400,
errorType: "BadRequestError",
message: "The request could not be understood."
}));
}
}
class UnauthorizedError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 401,
errorType: "UnauthorizedError",
message: "You are not authorised to make this request."
}));
}
}
class NoPermissionError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 403,
errorType: "NoPermissionError",
message: "You do not have permission to perform this request."
}));
}
}
class ValidationError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 422,
errorType: "ValidationError",
message: "The request failed validation."
}));
}
}
class UnsupportedMediaTypeError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 415,
errorType: "UnsupportedMediaTypeError",
message: "The media in the request is not supported by the server."
}));
}
}
class TooManyRequestsError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 429,
errorType: "TooManyRequestsError",
message: "Server has received too many similar requests in a short space of time."
}));
}
}
class MaintenanceError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 503,
errorType: "MaintenanceError",
message: "The server is temporarily down for maintenance."
}));
}
}
class MethodNotAllowedError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 405,
errorType: "MethodNotAllowedError",
message: "Method not allowed for resource."
}));
}
}
class RequestNotAcceptableError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 406,
errorType: "RequestNotAcceptableError",
message: "Request not acceptable for provided Accept-Version header.",
hideStack: true
}));
}
}
class RangeNotSatisfiableError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 416,
errorType: "RangeNotSatisfiableError",
message: "Range not satisfiable for provided Range header.",
hideStack: true
}));
}
}
class RequestEntityTooLargeError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 413,
errorType: "RequestEntityTooLargeError",
message: "Request was too big for the server to handle."
}));
}
}
class TokenRevocationError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 503,
errorType: "TokenRevocationError",
message: "Token is no longer available."
}));
}
}
class VersionMismatchError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 400,
errorType: "VersionMismatchError",
message: "Requested version does not match server version."
}));
}
}
class DataExportError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 500,
errorType: "DataExportError",
message: "The server encountered an error whilst exporting data."
}));
}
}
class DataImportError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 500,
errorType: "DataImportError",
message: "The server encountered an error whilst importing data."
}));
}
}
class EmailError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 500,
errorType: "EmailError",
message: "The server encountered an error whilst sending email."
}));
}
}
class ThemeValidationError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 422,
errorType: "ThemeValidationError",
message: "The theme has a validation error.",
errorDetails: {}
}));
}
}
class DisabledFeatureError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 409,
errorType: "DisabledFeatureError",
message: "Unable to complete the request, this feature is disabled."
}));
}
}
class UpdateCollisionError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
statusCode: 409,
errorType: "UpdateCollisionError",
message: "Unable to complete the request, there was a conflict."
}));
}
}
class HostLimitError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
errorType: "HostLimitError",
hideStack: true,
statusCode: 403,
message: "Unable to complete the request, this resource is limited."
}));
}
}
class HelperWarning extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
errorType: "HelperWarning",
hideStack: true,
statusCode: 400,
message: "A theme helper has done something unexpected."
}));
}
}
class PasswordResetRequiredError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
errorType: "PasswordResetRequiredError",
statusCode: 401,
message: "For security, you need to create a new password. An email has been sent to you with instructions!"
}));
}
}
class UnhandledJobError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
errorType: "UnhandledJobError",
message: "Processed job threw an unhandled error",
level: "critical"
}));
}
}
class NoContentError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
errorType: "NoContentError",
statusCode: 204,
hideStack: true
}));
}
}
class ConflictError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
errorType: "ConflictError",
statusCode: 409,
message: "The server has encountered an conflict."
}));
}
}
class MigrationError extends GhostError {
constructor(options = {}) {
super(mergeOptions(options, {
errorType: "MigrationError",
message: "An error has occurred applying a database migration.",
level: "critical"
}));
}
}
export {
BadRequestError,
ConflictError,
DataExportError,
DataImportError,
DisabledFeatureError,
EmailError,
HelperWarning,
HostLimitError,
IncorrectUsageError,
InternalServerError,
MaintenanceError,
MethodNotAllowedError,
MigrationError,
NoContentError,
NoPermissionError,
NotFoundError,
PasswordResetRequiredError,
RangeNotSatisfiableError,
RequestEntityTooLargeError,
RequestNotAcceptableError,
ThemeValidationError,
TokenRevocationError,
TooManyRequestsError,
UnauthorizedError,
UnhandledJobError,
UnsupportedMediaTypeError,
UpdateCollisionError,
ValidationError,
VersionMismatchError
};