-
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
Showing
10 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,13 +1,30 @@ | ||
class RowNotFoundError extends Error { | ||
constructor(msg: string) { | ||
class CustomError extends Error { | ||
readonly statusCode: number | undefined; | ||
|
||
constructor(msg: string, statusCode?: number) { | ||
super(msg); | ||
Object.setPrototypeOf(this, CustomError.prototype); | ||
|
||
this.statusCode = statusCode; | ||
} | ||
} | ||
|
||
class RowNotFoundError extends CustomError { | ||
constructor(msg: string, statusCode?: number) { | ||
super(msg, statusCode); | ||
Object.setPrototypeOf(this, RowNotFoundError.prototype); | ||
} | ||
} | ||
|
||
class InvalidTimeError extends Error { | ||
constructor(msg: string) { | ||
super(msg); | ||
class InvalidTimeError extends CustomError { | ||
constructor(msg: string, statusCode?: number) { | ||
super(msg, statusCode); | ||
Object.setPrototypeOf(this, InvalidTimeError.prototype); | ||
} | ||
} | ||
|
||
export { | ||
CustomError, | ||
RowNotFoundError, | ||
InvalidTimeError, | ||
} |
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,20 @@ | ||
import express, { ErrorRequestHandler } from "express"; | ||
import { CustomError } from "./errors"; | ||
import logger from "./logger"; | ||
|
||
const errorHandler: ErrorRequestHandler = (err, req, res, next) => { | ||
if (err instanceof CustomError && !!err.statusCode) { | ||
logger.warn(err.message) | ||
return res.status(err.statusCode).json({ | ||
description: err.message, | ||
}); | ||
} else { | ||
logger.error(err); | ||
return res.sendStatus(500); | ||
} | ||
} // TODO: Error handling | ||
|
||
export default { // TODO: CORS | ||
json: express.json(), | ||
errorHandler: errorHandler, | ||
} |
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