-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a decorator for custom errors and a domain-level error handler
- Loading branch information
Showing
5 changed files
with
61 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { StatusCodes } from 'http-status-codes'; | ||
import type { FastifyReply } from 'fastify'; | ||
|
||
/** | ||
* Custom method for sending 500 error | ||
* | ||
* Send this error when a domain-level error is thrown | ||
* | ||
* @example | ||
* | ||
* if (note.creatorId !== userId) { | ||
* return reply.domainError('Note with id ${id} was not updated'); | ||
* } | ||
* | ||
* @param message - custom message | ||
*/ | ||
export default async function domainError(this: FastifyReply, message = 'Domain level error'): Promise<void> { | ||
await this | ||
.code(StatusCodes.INTERNAL_SERVER_ERROR) | ||
.type('application/json') | ||
.send({ | ||
message, | ||
}); | ||
} |
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