mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
comment errors according to apidoc, add new tests and fix existing ones
This commit is contained in:
@@ -7,8 +7,17 @@ export class CustomError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
// NotAuthorized error with a 401 http error code
|
||||
// used when a request is not authorized
|
||||
/**
|
||||
* @apiDefine NotFound
|
||||
* @apiError NotFound The client is not authorized to make this request.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 401 Unauthorized
|
||||
* {
|
||||
* "error": "NotAuthorized",
|
||||
* "message": "Not authorized."
|
||||
* }
|
||||
*/
|
||||
export class NotAuthorized extends CustomError {
|
||||
constructor (customMessage) {
|
||||
super();
|
||||
@@ -18,10 +27,18 @@ export class NotAuthorized extends CustomError {
|
||||
}
|
||||
}
|
||||
|
||||
// BadRequest error with a 400 http error code
|
||||
// used for requests not formatted correctly
|
||||
// TODO use for validation errors too?
|
||||
export class BadRequest extends CustomError {
|
||||
/**
|
||||
* @apiDefine BadRequest
|
||||
* @apiError BadRequest The request wasn't formatted correctly.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 400 Bad Request
|
||||
* {
|
||||
* "error": "BadRequest",
|
||||
* "message": "Bad request."
|
||||
* }
|
||||
*/
|
||||
export class BadRequest extends CustomError {
|
||||
constructor (customMessage) {
|
||||
super();
|
||||
this.name = this.constructor.name;
|
||||
@@ -37,25 +54,35 @@ export class BadRequest extends CustomError {
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "error": "NotFound"
|
||||
* "error": "NotFound",
|
||||
* "message": "Not found."
|
||||
* }
|
||||
*/
|
||||
export class NotFound extends CustomError {
|
||||
constructor (customMessage) {
|
||||
super();
|
||||
this.name = this.constructor.name;
|
||||
this.httpCode = 401;
|
||||
this.httpCode = 404;
|
||||
this.message = customMessage || 'Not found.';
|
||||
}
|
||||
}
|
||||
|
||||
// InternalError error with a 500 http error code
|
||||
// used when an unexpected, internal server error is thrown
|
||||
/**
|
||||
* @apiDefine InternalServerError
|
||||
* @apiError InternalServerError An unexpected error occurred.
|
||||
*
|
||||
* @apiErrorExample Error-Response:
|
||||
* HTTP/1.1 500 Internal Server Error
|
||||
* {
|
||||
* "error": "InternalServerError",
|
||||
* "message": "An unexpected error occurred."
|
||||
* }
|
||||
*/
|
||||
export class InternalServerError extends CustomError {
|
||||
constructor (customMessage) {
|
||||
super();
|
||||
this.name = this.constructor.name;
|
||||
this.httpCode = 500;
|
||||
this.message = customMessage || 'Internal server error.';
|
||||
this.message = customMessage || 'An unexpected error occurred.';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user