-
Notifications
You must be signed in to change notification settings - Fork 7
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
9 changed files
with
149 additions
and
10 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
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,45 @@ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
/** | ||
* | ||
* | ||
* @export | ||
* @class ResponseHandler | ||
*/ | ||
export default class ResponseHandler { | ||
/** | ||
* | ||
* | ||
* @static | ||
* @param {*} res HTTP response object | ||
* @param {*} data An object or array to send as a response | ||
* @param {number} [status=200] HTTP response status code. Default is 200 | ||
* @memberof ResponseHandler | ||
* @returns {void} | ||
*/ | ||
static success(res, data, status = 200) { | ||
return res.status(status).json({ | ||
success: true, | ||
status, | ||
data | ||
}); | ||
} | ||
|
||
/** | ||
* | ||
* | ||
* @static | ||
* @param {*} res HTTP response object | ||
* @param {string} [message='Bad request'] An error message | ||
* @param {number} [status=400] HTTP response status code. Default is 400 | ||
* @memberof ResponseHandler | ||
* @returns {void} | ||
*/ | ||
static error(res, message = 'Bad request', status = 400) { | ||
return res.status(status).json({ | ||
success: false, | ||
status, | ||
error: message | ||
}); | ||
} | ||
} |