errors.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { ID } from '../../../../shared/shared-types';
  2. import { coreEntitiesMap } from '../../entity/entities';
  3. import { I18nError } from '../../i18n/i18n-error';
  4. export class InternalServerError extends I18nError {
  5. constructor(message: string, variables: { [key: string]: string | number } = {}) {
  6. super(message, variables, 'INTERNAL_SERVER_ERROR');
  7. }
  8. }
  9. export class UserInputError extends I18nError {
  10. constructor(message: string, variables: { [key: string]: string | number } = {}) {
  11. super(message, variables, 'USER_INPUT_ERROR');
  12. }
  13. }
  14. export class IllegalOperationError extends I18nError {
  15. constructor(message: string, variables: { [key: string]: string | number } = {}) {
  16. super(message, variables, 'ILLEGAL_OPERATION');
  17. }
  18. }
  19. export class UnauthorizedError extends I18nError {
  20. constructor() {
  21. super('error.unauthorized', {}, 'UNAUTHORIZED');
  22. }
  23. }
  24. export class ForbiddenError extends I18nError {
  25. constructor() {
  26. super('error.forbidden', {}, 'FORBIDDEN');
  27. }
  28. }
  29. export class NoValidChannelError extends I18nError {
  30. constructor() {
  31. super('error.no-valid-channel-specified', {}, 'NO_VALID_CHANNEL');
  32. }
  33. }
  34. export class ChannelNotFoundError extends I18nError {
  35. constructor(token: string) {
  36. super('error.channel-not-found', { token }, 'CHANNEL_NOT_FOUND');
  37. }
  38. }
  39. export class EntityNotFoundError extends I18nError {
  40. constructor(entityName: keyof typeof coreEntitiesMap, id: ID) {
  41. super('error.entity-with-id-not-found', { entityName, id }, 'ENTITY_NOT_FOUND');
  42. }
  43. }
  44. export class VerificationTokenError extends I18nError {
  45. constructor() {
  46. super('error.verification-token-not-recognized', {}, 'BAD_VERIFICATION_TOKEN');
  47. }
  48. }
  49. export class VerificationTokenExpiredError extends I18nError {
  50. constructor() {
  51. super('error.verification-token-has-expired', {}, 'EXPIRED_VERIFICATION_TOKEN');
  52. }
  53. }
  54. export class PasswordResetTokenError extends I18nError {
  55. constructor() {
  56. super('error.password-reset-token-not-recognized', {}, 'BAD_PASSWORD_RESET_TOKEN');
  57. }
  58. }
  59. export class PasswordResetTokenExpiredError extends I18nError {
  60. constructor() {
  61. super('error.password-reset-token-has-expired', {}, 'EXPIRED_PASSWORD_RESET_TOKEN');
  62. }
  63. }
  64. export class NotVerifiedError extends I18nError {
  65. constructor() {
  66. super('error.email-address-not-verified', {}, 'NOT_VERIFIED');
  67. }
  68. }
  69. export class OrderItemsLimitError extends I18nError {
  70. constructor(maxItems: number) {
  71. super('error.order-items-limit-exceeded', { maxItems }, 'ORDER_ITEMS_LIMIT_EXCEEDED');
  72. }
  73. }