-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85e759d
commit a085c73
Showing
9 changed files
with
91 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import fastify, { FastifyReply, FastifyRequest } from 'fastify'; | ||
Check warning on line 1 in src/plugins/errorHandler.ts GitHub Actions / Run Unit Tests
|
||
import fp from 'fastify-plugin'; | ||
import { BaseError, InternalServerError, NotFoundError } from '../errors/index.js'; | ||
import { request } from 'http'; | ||
|
||
const errorHandlerPlugin = fp(async(fastify) => { | ||
fastify.setErrorHandler((err: unknown, request: FastifyRequest, reply: FastifyReply) => { | ||
let finalErr = new InternalServerError(); | ||
if (err instanceof BaseError) { | ||
finalErr = err; | ||
} | ||
if (err instanceof BaseError) { | ||
request.log.error({errId: err.id, errName: err.name}, finalErr.toString()) | ||
} else if (err instanceof Error) { | ||
request.log.error({errName: err.name}, 'Native unhandled error: response sent to client.') | ||
} else { | ||
request.log.error('Native unhandled error: response sent to client.') | ||
} | ||
reply.status(finalErr.httpStatusCode).type('application/json').send({ | ||
error: true, | ||
name: finalErr.name, | ||
id: finalErr.id, | ||
message: finalErr.message, | ||
}) | ||
}) | ||
fastify.setNotFoundHandler((request: FastifyRequest) => { | ||
throw new NotFoundError({endpointName: request.url}); | ||
}) | ||
}) | ||
|
||
export default errorHandlerPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
export enum EventsApiRoles { | ||
export enum AppRoles { | ||
MANAGER, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters