mirror of
https://github.com/strapi/strapi.git
synced 2025-07-26 18:38:46 +00:00
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const { HttpError } = require('http-errors');
|
|
const { formatYupErrors } = require('./format-yup-error');
|
|
|
|
/* ApplicationError */
|
|
class ApplicationError extends Error {
|
|
constructor(message, details = {}) {
|
|
super();
|
|
this.name = 'ApplicationError';
|
|
this.message = message || 'An application error occured';
|
|
this.details = details;
|
|
}
|
|
}
|
|
|
|
class ValidationError extends ApplicationError {
|
|
constructor(message, details) {
|
|
super(message, details);
|
|
this.name = 'ValidationError';
|
|
}
|
|
}
|
|
|
|
class YupValidationError extends ApplicationError {
|
|
constructor(yupError, message) {
|
|
super();
|
|
const { errors, message: yupMessage } = formatYupErrors(yupError);
|
|
this.name = 'ValidationError';
|
|
this.message = message || yupMessage;
|
|
this.details = { errors };
|
|
}
|
|
}
|
|
|
|
class PaginationError extends ApplicationError {
|
|
constructor(message, details = {}) {
|
|
super(message, details);
|
|
this.name = 'PaginationError';
|
|
this.message = message || 'Invalid pagination';
|
|
}
|
|
}
|
|
|
|
class QueryError extends ApplicationError {
|
|
constructor(message, details) {
|
|
super(message, details);
|
|
this.name = 'QueryError';
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
HttpError,
|
|
ApplicationError,
|
|
ValidationError,
|
|
YupValidationError,
|
|
PaginationError,
|
|
QueryError,
|
|
};
|