1- import ApiResponse from "./api-response " ;
1+ import { Response } from "express " ;
22
3- export function ApplicationError ( code : number , type : string , message : string ) : ApiResponse {
4- return {
3+ export function ApplicationError ( res : Response , code : number , type : string , message : string ) {
4+ return res . status ( code ) . json ( {
55 success : false ,
66 error : {
77 code,
88 type,
99 message
1010 }
11- }
11+ } ) ;
1212}
1313
14- export function InvalidFormDataError ( message : string = 'Invalid form data!' ) {
15- return ApplicationError ( 400 , 'InvalidFormData' , message ) ;
14+ export function InvalidFormDataError ( res : Response , message : string = 'Invalid form data!' ) {
15+ return ApplicationError ( res , 400 , 'InvalidFormData' , message ) ;
1616}
1717
18- export function AuthenticationError ( message : string = 'User is not Authenticated!' ) {
19- return ApplicationError ( 401 , 'AuthenticationError' , message ) ;
18+ export function AuthenticationError ( res : Response , message : string = 'User is not Authenticated!' ) {
19+ return ApplicationError ( res , 401 , 'AuthenticationError' , message ) ;
2020}
2121
22- export function ForbiddenError ( message : string = 'User is forbidden from accessing this resource!' ) {
23- return ApplicationError ( 403 , 'ForbiddenError' , message ) ;
22+ export function ForbiddenError ( res : Response , message : string = 'User is forbidden from accessing this resource!' ) {
23+ return ApplicationError ( res , 403 , 'ForbiddenError' , message ) ;
2424}
2525
26- export function NotFoundError ( message : string = 'The resource you were looking for was not found on this server.' ) {
27- return ApplicationError ( 404 , 'NotFoundError' , message ) ;
26+ export function NotFoundError ( res : Response , message : string = 'The resource you were looking for was not found on this server.' ) {
27+ return ApplicationError ( res , 404 , 'NotFoundError' , message ) ;
2828}
2929
30- export function ConflictError ( message : string = 'The resource you are trying to create already exists!' ) {
31- return ApplicationError ( 409 , 'Conflict' , message ) ;
30+ export function ConflictError ( res : Response , message : string = 'The resource you are trying to create already exists!' ) {
31+ return ApplicationError ( res , 409 , 'Conflict' , message ) ;
3232}
3333
34- export function ServerError ( message : string = 'Server Error!' ) {
35- return ApplicationError ( 500 , 'ServerError' , message ) ;
34+ export function ServerError ( res : Response , message : string = 'Server Error!' ) {
35+ return ApplicationError ( res , 500 , 'ServerError' , message ) ;
3636}
0 commit comments