refactor: migrate to typescript

This commit is contained in:
Elliot DeNolf
2020-11-20 13:39:18 -05:00
parent 38028dd36b
commit 551c249e39
451 changed files with 1240 additions and 593 deletions

37
src/errors/APIError.ts Normal file
View File

@@ -0,0 +1,37 @@
/* eslint-disable max-classes-per-file */
const httpStatus = require('http-status');
/**
* @extends Error
*/
class ExtendableError extends Error {
constructor(message, status, data, isPublic) {
super(message);
this.name = this.constructor.name;
this.message = message;
this.status = status;
this.data = data;
this.isPublic = isPublic;
this.isOperational = true; // This is required since bluebird 4 doesn't append it anymore.
Error.captureStackTrace(this, this.constructor.name);
}
}
/**
* Class representing an API error.
* @extends ExtendableError
*/
class APIError extends ExtendableError {
/**
* Creates an API error.
* @param {string} message - Error message.
* @param {number} status - HTTP status code of error.
* @param {object} data - response data to be returned.
* @param {boolean} isPublic - Whether the message should be visible to user or not.
*/
constructor(message, status = httpStatus.INTERNAL_SERVER_ERROR, data, isPublic = false) {
super(message, status, data, isPublic);
}
}
module.exports = APIError;