AI Implementation feature(820): Project Scaffold and Platform Foundations (#1)
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { ErrorCode, ERROR_CODES } from './error-codes';
|
||||
|
||||
export class ApiError extends HttpException {
|
||||
constructor(
|
||||
public readonly code: ErrorCode,
|
||||
message: string,
|
||||
status: HttpStatus,
|
||||
public readonly details?: unknown,
|
||||
) {
|
||||
super({ code, message, details }, status);
|
||||
}
|
||||
|
||||
static validation(message = 'Validation failed', details?: unknown): ApiError {
|
||||
return new ApiError(ERROR_CODES.VALIDATION_FAILED, message, HttpStatus.BAD_REQUEST, details);
|
||||
}
|
||||
|
||||
static unauthorized(message = 'Unauthorized'): ApiError {
|
||||
return new ApiError(ERROR_CODES.UNAUTHORIZED, message, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
static forbidden(message = 'Forbidden'): ApiError {
|
||||
return new ApiError(ERROR_CODES.FORBIDDEN, message, HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
static notFound(message = 'Not found'): ApiError {
|
||||
return new ApiError(ERROR_CODES.NOT_FOUND, message, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
static conflict(code: ErrorCode, message: string): ApiError {
|
||||
return new ApiError(code, message, HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
static internal(message = 'Internal server error'): ApiError {
|
||||
return new ApiError(ERROR_CODES.INTERNAL, message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user