Files
speckle-server/packages/server/modules/shared/errors/index.ts
T
Iain Sproat 6715a030ec fix(server/auth): database errors result in 500 status code (#2731)
* fix(server/auth): database errors result in 500 status code
- previously 401 were returned which resulted in connectors not retrying

* log as info, not error. Handle errors while validating read

* Unknown errors should continue to be bubbled up the stack
2024-08-22 15:39:37 +02:00

92 lines
2.8 KiB
TypeScript

import { BaseError, Info } from '@/modules/shared/errors/base'
/**
* Use this to throw when the request has auth credentials, but they are not sufficient
*/
export class ForbiddenError extends BaseError {
static code = 'FORBIDDEN'
static defaultMessage = 'Access to the resource is forbidden'
static statusCode = 403
}
/**
* Use this in logic branches that should never execute, and if they do - it means
* there's most definitely a bug in the code
*/
export class LogicError extends BaseError {
static code = 'LOGIC_ERROR'
static defaultMessage = 'An unexpected issue occurred'
}
/**
* Use this to throw when the request lacks valid authentication credentials
*/
export class UnauthorizedError extends BaseError {
static code = 'UNAUTHORIZED_ACCESS_ERROR'
static defaultMessage = 'Attempted unauthorized access to data'
static statusCode = 401
}
export class NotFoundError extends BaseError {
static code = 'NOT_FOUND_ERROR'
static defaultMessage = "These aren't the droids you're looking for."
}
export class BadRequestError extends BaseError {
static code = 'BAD_REQUEST_ERROR'
static defaultMessage = 'The request contains invalid data'
}
export class ResourceMismatch extends BaseError {
static code = 'BAD_REQUEST_ERROR'
static defaultMessage = 'The target resources mismatch'
}
/**
* Use this to validate args
*/
export class InvalidArgumentError extends BaseError {
static code = 'INVALID_ARGUMENT_ERROR'
static defaultMessage = 'Invalid arguments received'
}
export class RichTextParseError extends BaseError {
static code = 'RICH_TEXT_PARSE_ERROR'
static defaultMessage =
'An error occurred while trying to parse the rich text document'
}
export class ContextError extends BaseError {
static code = 'CONTEXT_ERROR'
static defaultMessage = 'The context is missing from the request'
}
export class MisconfiguredEnvironmentError extends BaseError {
static code = 'MISCONFIGURED_ENVIRONMENT_ERROR'
static defaultMessage =
'An error occurred due to the server environment being misconfigured'
}
export class UninitializedResourceAccessError extends BaseError {
static code = 'UNINITIALIZED_RESOURCE_ACCESS_ERROR'
static defaultMessage = 'Attempted to use uninitialized resources'
}
export class UnexpectedErrorStructureError extends BaseError {
static code = 'UNEXPECTED_ERROR_STRUCTURE_ERROR'
static defaultMessage = 'An unexpected error type was thrown'
}
export class EnvironmentResourceError extends BaseError {
static code = 'ENVIRONMENT_RESOURCE_ERROR'
static defaultMessage =
'An error occurred while trying to access a resource in the environment.'
}
export class DatabaseError extends BaseError {
static code = 'DATABASE_ERROR'
static defaultMessage = 'An error occurred while trying to access the database.'
}
export { BaseError }
export type { Info }