diff --git a/src/controllers/CampaignController.js b/src/controllers/CampaignController.js index 44aee146..1db5c2a6 100644 --- a/src/controllers/CampaignController.js +++ b/src/controllers/CampaignController.js @@ -80,6 +80,7 @@ class CampaignController { } async finishCampaign(req, res) { + const { id } = req.params; if(!id) throw new BadRequestError('No id provided'); const result = await this.CampaignService.finishCampaign(id); return res.status(200).json(result); diff --git a/src/utils/errorHandler.js b/src/utils/errorHandler.js index f3f4ed8f..6eb2caa2 100644 --- a/src/utils/errorHandler.js +++ b/src/utils/errorHandler.js @@ -1,6 +1,6 @@ import saveError from "./ErrorHistory"; -export const errorHandler = (err, req, res, next) => { +export const errorHandler = (err, _req, res, _next) => { if(err instanceof GeneralError) { return res.status(err.getCode()).json({ status: 'error', @@ -21,17 +21,14 @@ export class GeneralError extends Error { } getCode() { - if(this instanceof BadRequestError) return 400; - else if(this instanceof UnauthorizedError) return 404; - else if(this instanceof ForbiddenError) return 404; - else if(this instanceof NotFoundError) return 404; - else if(this instanceof ConflictError) return 409; + return this.code; } } export class BadRequestError extends GeneralError { constructor(msg) { super(msg); + this.code = 400; this.name = `BadRequestError:${msg}`; } } @@ -39,6 +36,7 @@ export class BadRequestError extends GeneralError { export class UnauthorizedError extends GeneralError { constructor(msg) { super(msg); + this.code = 401; this.name = `UnauthorizedError:${msg}`; } } @@ -46,6 +44,7 @@ export class UnauthorizedError extends GeneralError { export class ForbiddenError extends GeneralError { constructor(msg) { super(msg); + this.code = 403; this.name = `ForbiddenError:${msg}`; } } @@ -53,6 +52,7 @@ export class ForbiddenError extends GeneralError { export class NotFoundError extends GeneralError { constructor(msg) { super(msg); + this.code = 404; this.name = `NotFoundError:${msg}`; } } @@ -60,6 +60,7 @@ export class NotFoundError extends GeneralError { export class ConflictError extends GeneralError { constructor(msg) { super(msg); + this.code = 409; this.name = `ConflictError:${msg}`; } } \ No newline at end of file