@lbu/server
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -7,5 +7,4 @@ import compose from "koa-compose"; | ||
createBodyParsers, | ||
AppError, | ||
isServerLog, | ||
session, | ||
} from "./src/middleware/index.js"; |
{ | ||
"name": "@lbu/server", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Koa server and common middleware", | ||
@@ -18,4 +18,4 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@lbu/insight": "^0.0.14", | ||
"@lbu/stdlib": "^0.0.14", | ||
"@lbu/insight": "^0.0.15", | ||
"@lbu/stdlib": "^0.0.15", | ||
"keygrip": "1.1.0", | ||
@@ -41,3 +41,3 @@ "koa": "2.11.0", | ||
}, | ||
"gitHead": "07129065a222685632bef708ce5051ff5f658ae8" | ||
"gitHead": "2f0f45592d7a0471397cc5d409f6e651f2b59b90" | ||
} |
@@ -1,81 +0,4 @@ | ||
import { isNil } from "@lbu/stdlib"; | ||
import { AppError, isNil } from "@lbu/stdlib"; | ||
/** | ||
* AppErrors represent errors, that should immediately stop the request and return a | ||
* status and other meta data directly | ||
*/ | ||
export class AppError extends Error { | ||
/** | ||
* Create a new AppError | ||
* @param {string} key | ||
* @param {number} status | ||
* @param {Object} [info={}] | ||
* @param {Error} [originalError] | ||
*/ | ||
constructor(key, status, info, originalError) { | ||
super(); | ||
this.key = key; | ||
this.status = status; | ||
this.info = info || {}; | ||
this.originalError = originalError; | ||
Object.setPrototypeOf(this, AppError.prototype); | ||
if (isNil(key) || isNil(status)) { | ||
return AppError.serverError( | ||
{ | ||
appErrorConstruct: { | ||
key, | ||
status, | ||
}, | ||
}, | ||
this, | ||
); | ||
} | ||
} | ||
/** | ||
* Throw a new 404 not found error | ||
* @param {Object} [info={}] | ||
* @param {Error} [error] | ||
* @return {AppError} | ||
*/ | ||
static notFound(info = {}, error = undefined) { | ||
return new AppError("error.server.notFound", 404, info, error); | ||
} | ||
/** | ||
* Throw a new 405 Not implemented error | ||
* @param {Object} [info={}] | ||
* @param {Error} [error] | ||
* @return {AppError} | ||
*/ | ||
static notImplemented(info = {}, error = undefined) { | ||
return new AppError("error.server.notImplemented", 405, info, error); | ||
} | ||
/** | ||
* Throw a new 500 internal server error | ||
* @param {Object} [info={}] | ||
* @param {Error} [error] | ||
* @return {AppError} | ||
*/ | ||
static serverError(info = {}, error = undefined) { | ||
return new AppError("error.server.internal", 500, info, error); | ||
} | ||
/** | ||
* Throw a new 400 validation error | ||
* @param {string} key | ||
* @param {Object} [info={}] | ||
* @param {Error} [error] | ||
* @return {AppError} | ||
*/ | ||
static validationError(key, info = {}, error = undefined) { | ||
return new AppError(key, 400, info, error); | ||
} | ||
} | ||
/** | ||
* @callback CustomErrorHandler | ||
@@ -82,0 +5,0 @@ * @param ctx Koa Context |
export { createBodyParsers } from "./body.js"; | ||
export { AppError, errorHandler } from "./error.js"; | ||
export { errorHandler } from "./error.js"; | ||
export { defaultHeaders } from "./headers.js"; | ||
@@ -4,0 +4,0 @@ export { healthHandler } from "./health.js"; |
@@ -1,2 +0,2 @@ | ||
import { AppError } from "./error.js"; | ||
import { AppError } from "@lbu/stdlib"; | ||
@@ -3,0 +3,0 @@ /** |
16791
441
+ Added@lbu/insight@0.0.15(transitive)
+ Added@lbu/stdlib@0.0.15(transitive)
- Removed@lbu/insight@0.0.14(transitive)
- Removed@lbu/stdlib@0.0.14(transitive)
Updated@lbu/insight@^0.0.15
Updated@lbu/stdlib@^0.0.15