Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/payload/src/errors/APIError.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { status as httpStatus } from 'http-status'

// This gets dynamically reassigned during compilation
export let APIErrorName = 'APIError'
/**
* @deprecated Remove this in 4.0 - this is no longer needed as we assign the prototype correctly in the constructor
*/
export const APIErrorName = 'APIError'

class ExtendableError<TData extends object = { [key: string]: unknown }> extends Error {
data: TData
Expand All @@ -17,13 +19,17 @@ class ExtendableError<TData extends object = { [key: string]: unknown }> extends
// show data in cause
cause: data,
})
APIErrorName = this.constructor.name
this.name = this.constructor.name
this.message = message
this.status = status
this.data = data
this.isPublic = isPublic
this.isOperational = true // This is required since bluebird 4 doesn't append it anymore.

// Ensure error name is not lost during swc minification when running next build
this.name = 'ExtendableError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, ExtendableError.prototype)

Error.captureStackTrace(this, this.constructor)
}
}
Expand All @@ -50,5 +56,10 @@ export class APIError<
isPublic = false,
) {
super(message, status, data, isPublic)

// Ensure error name is not lost during swc minification when running next build
this.name = 'APIError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, APIError.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/AuthenticationError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ export class AuthenticationError extends APIError {
: en.translations.error.emailOrPasswordIncorrect,
httpStatus.UNAUTHORIZED,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'AuthenticationError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, AuthenticationError.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/DuplicateCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ import { APIError } from './APIError.js'
export class DuplicateCollection extends APIError {
constructor(propertyName: string, duplicate: string) {
super(`Collection ${propertyName} already in use: "${duplicate}"`)

// Ensure error name is not lost during swc minification when running next build
this.name = 'DuplicateCollection'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, DuplicateCollection.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/DuplicateFieldName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ export class DuplicateFieldName extends APIError {
super(
`A field with the name '${fieldName}' was found multiple times on the same level. Field names must be unique.`,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'DuplicateFieldName'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, DuplicateFieldName.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/DuplicateGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ import { APIError } from './APIError.js'
export class DuplicateGlobal extends APIError {
constructor(config: GlobalConfig) {
super(`Global label "${config.label}" is already in use`)

// Ensure error name is not lost during swc minification when running next build
this.name = 'DuplicateGlobal'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, DuplicateGlobal.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/ErrorDeletingFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ export class ErrorDeletingFile extends APIError {
t ? t('error:deletingFile') : en.translations.error.deletingFile,
httpStatus.INTERNAL_SERVER_ERROR,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'ErrorDeletingFile'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, ErrorDeletingFile.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/FileRetrievalError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ export class FileRetrievalError extends APIError {
msg += ` ${message}`
}
super(msg, httpStatus.INTERNAL_SERVER_ERROR)

// Ensure error name is not lost during swc minification when running next build
this.name = 'FileRetrievalError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, FileRetrievalError.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/FileUploadError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ export class FileUploadError extends APIError {
t ? t('error:problemUploadingFile') : en.translations.error.problemUploadingFile,
httpStatus.BAD_REQUEST,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'FileUploadError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, FileUploadError.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/Forbidden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ export class Forbidden extends APIError {
t ? t('error:notAllowedToPerformAction') : en.translations.error.notAllowedToPerformAction,
httpStatus.FORBIDDEN,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'Forbidden'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, Forbidden.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/InvalidConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ import { APIError } from './APIError.js'
export class InvalidConfiguration extends APIError {
constructor(message: string) {
super(message, httpStatus.INTERNAL_SERVER_ERROR)

// Ensure error name is not lost during swc minification when running next build
this.name = 'InvalidConfiguration'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, InvalidConfiguration.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/InvalidFieldJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ export class InvalidFieldJoin extends APIError {
super(
`Invalid join field ${field.name}. The config does not have a field '${field.on}' in collection '${field.collection}'.`,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'InvalidFieldJoin'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, InvalidFieldJoin.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/InvalidFieldName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ export class InvalidFieldName extends APIError {
super(
`Field ${field.label} has invalid name '${fieldName}'. Field names can not include periods (.) and must be alphanumeric.`,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'InvalidFieldName'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, InvalidFieldName.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/InvalidFieldRelationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ import { APIError } from './APIError.js'
export class InvalidFieldRelationship extends APIError {
constructor(field: RelationshipField | UploadField, relationship: string) {
super(`Field ${field.label} has invalid relationship '${relationship}'.`)

// Ensure error name is not lost during swc minification when running next build
this.name = 'InvalidFieldRelationship'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, InvalidFieldRelationship.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/InvalidSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ import { APIError } from './APIError.js'
export class InvalidSchema extends APIError {
constructor(message: string, results: any) {
super(message, httpStatus.INTERNAL_SERVER_ERROR, results)

// Ensure error name is not lost during swc minification when running next build
this.name = 'InvalidSchema'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, InvalidSchema.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/Locked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ import { APIError } from './APIError.js'
export class Locked extends APIError {
constructor(message: string) {
super(message, httpStatus.LOCKED)

// Ensure error name is not lost during swc minification when running next build
this.name = 'Locked'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, Locked.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/LockedAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ import { APIError } from './APIError.js'
export class LockedAuth extends APIError {
constructor(t?: TFunction) {
super(t ? t('error:userLocked') : en.translations.error.userLocked, httpStatus.UNAUTHORIZED)

// Ensure error name is not lost during swc minification when running next build
this.name = 'LockedAuth'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, LockedAuth.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/MissingCollectionLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ import { APIError } from './APIError.js'
export class MissingCollectionLabel extends APIError {
constructor() {
super('payload.config.collection object is missing label')

// Ensure error name is not lost during swc minification when running next build
this.name = 'MissingCollectionLabel'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, MissingCollectionLabel.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/MissingEditorProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ export class MissingEditorProp extends APIError {
super(
`RichText field${fieldAffectsData(field) ? ` "${field.name}"` : ''} is missing the editor prop. For sub-richText fields, the editor props is required, as it would otherwise create infinite recursion.`,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'MissingEditorProp'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, MissingEditorProp.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/MissingFieldInputOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ import { APIError } from './APIError.js'
export class MissingFieldInputOptions extends APIError {
constructor(field: RadioField | SelectField) {
super(`Field ${field.label} is missing options.`)

// Ensure error name is not lost during swc minification when running next build
this.name = 'MissingFieldInputOptions'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, MissingFieldInputOptions.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/MissingFieldType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ export class MissingFieldType extends APIError {
fieldAffectsData(field) ? ` "${field.name}"` : ''
} is either missing a field type or it does not match an available field type`,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'MissingFieldType'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, MissingFieldType.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/MissingFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ export class MissingFile extends APIError {
t ? t('error:noFilesUploaded') : en.translations.error.noFilesUploaded,
httpStatus.BAD_REQUEST,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'MissingFile'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, MissingFile.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/NotFound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ import { APIError } from './APIError.js'
export class NotFound extends APIError {
constructor(t?: TFunction) {
super(t ? t('general:notFound') : en.translations.general.notFound, httpStatus.NOT_FOUND)

// Ensure error name is not lost during swc minification when running next build
this.name = 'NotFound'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, NotFound.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/QueryError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ export class QueryError extends APIError<{ path: string }[]> {
httpStatus.BAD_REQUEST,
results,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'QueryError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, QueryError.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/ReservedFieldName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ import { APIError } from './APIError.js'
export class ReservedFieldName extends APIError {
constructor(field: FieldAffectingData, fieldName: string) {
super(`Field ${field.label} has reserved name '${fieldName}'.`)

// Ensure error name is not lost during swc minification when running next build
this.name = 'ReservedFieldName'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, ReservedFieldName.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/TimestampsRequired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ export class TimestampsRequired extends APIError {
super(
`Timestamps are required in the collection ${collection.slug} because you have opted in to Versions.`,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'TimestampsRequired'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, TimestampsRequired.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/UnauthorizedError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ import { APIError } from './APIError.js'
export class UnauthorizedError extends APIError {
constructor(t?: TFunction) {
super(t ? t('error:unauthorized') : en.translations.error.unauthorized, httpStatus.UNAUTHORIZED)

// Ensure error name is not lost during swc minification when running next build
this.name = 'UnauthorizedError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, UnauthorizedError.prototype)
}
}
5 changes: 5 additions & 0 deletions packages/payload/src/errors/UnverifiedEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ export class UnverifiedEmail extends APIError {
t ? t('error:unverifiedEmail') : en.translations.error.unverifiedEmail,
httpStatus.FORBIDDEN,
)

// Ensure error name is not lost during swc minification when running next build
this.name = 'UnverifiedEmail'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, UnverifiedEmail.prototype)
}
}
11 changes: 8 additions & 3 deletions packages/payload/src/errors/ValidationError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import type { PayloadRequest } from '../types/index.js'

import { APIError } from './APIError.js'

// This gets dynamically reassigned during compilation
export let ValidationErrorName = 'ValidationError'
/**
* @deprecated Remove this in 4.0 - this is no longer needed as we assign the prototype correctly in the constructor
*/
export const ValidationErrorName = 'ValidationError'

export type ValidationFieldError = {
label?: LabelFunction | StaticLabel
Expand Down Expand Up @@ -76,6 +78,9 @@ export class ValidationError extends APIError<{
results,
)

ValidationErrorName = this.constructor.name
// Ensure error name is not lost during swc minification when running next build
this.name = 'ValidationError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, ValidationError.prototype)
}
}
15 changes: 15 additions & 0 deletions packages/payload/src/queues/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export class TaskError extends Error {
constructor(args: TaskErrorArgs) {
super(args.message)
this.args = args

// Ensure error name is not lost during swc minification when running next build
this.name = 'TaskError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, TaskError.prototype)
}
}
export class WorkflowError extends Error {
Expand All @@ -36,6 +41,11 @@ export class WorkflowError extends Error {
constructor(args: WorkflowErrorArgs) {
super(args.message)
this.args = args

// Ensure error name is not lost during swc minification when running next build
this.name = 'WorkflowError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, WorkflowError.prototype)
}
}

Expand All @@ -47,5 +57,10 @@ export class JobCancelledError extends Error {
constructor(args: { job: Job }) {
super(`Job ${args.job.id} was cancelled`)
this.args = args

// Ensure error name is not lost during swc minification when running next build
this.name = 'JobCancelledError'
// Ensure instanceof works correctly
Object.setPrototypeOf(this, JobCancelledError.prototype)
}
}
Loading
Loading