appolo-agent
Advanced tools
Comparing version 6.0.0 to 6.0.1
@@ -6,4 +6,8 @@ "use strict"; | ||
exports.Agent = agent_2.Agent; | ||
var httpError_1 = require("./lib/httpError"); | ||
var httpError_1 = require("./lib/errors/httpError"); | ||
exports.HttpError = httpError_1.HttpError; | ||
var badRequestError_1 = require("./lib/errors/badRequestError"); | ||
exports.BadRequestError = badRequestError_1.BadRequestError; | ||
var internalServerError_1 = require("./lib/errors/internalServerError"); | ||
exports.InternalServerError = internalServerError_1.InternalServerError; | ||
var appolo_route_1 = require("appolo-route"); | ||
@@ -10,0 +14,0 @@ exports.Methods = appolo_route_1.Methods; |
@@ -7,3 +7,5 @@ import {IOptions} from "./lib/IOptions"; | ||
export {IApp} from './lib/IApp' | ||
export {HttpError} from './lib/httpError' | ||
export {HttpError} from './lib/errors/httpError' | ||
export {BadRequestError} from './lib/errors/badRequestError' | ||
export {InternalServerError} from './lib/errors/internalServerError' | ||
export {IRequest} from './lib/request' | ||
@@ -10,0 +12,0 @@ export {IResponse} from './lib/response' |
@@ -7,3 +7,3 @@ "use strict"; | ||
const response_1 = require("./response"); | ||
const httpError_1 = require("./httpError"); | ||
const httpError_1 = require("./errors/httpError"); | ||
const util_1 = require("./util"); | ||
@@ -128,3 +128,3 @@ const errorHandler_1 = require("./errorHandler"); | ||
catch (e) { | ||
if (e.code !== "ERR_SERVER_NOT_RUNNING") { | ||
if (e.message !== "Not running" && e.code !== "ERR_SERVER_NOT_RUNNING") { | ||
throw e; | ||
@@ -131,0 +131,0 @@ } |
@@ -5,3 +5,3 @@ import {IOptions} from "./IOptions"; | ||
import {createResponse, IResponse} from "./response"; | ||
import {HttpError} from "./httpError"; | ||
import {HttpError} from "./errors/httpError"; | ||
import {Util} from "./util"; | ||
@@ -179,3 +179,3 @@ import {MiddlewareHandler, MiddlewareHandlerAny, MiddlewareHandlerParams, NextFn} from "./types"; | ||
} catch (e) { | ||
if (e.code !== "ERR_SERVER_NOT_RUNNING") { | ||
if (e.message !=="Not running" && e.code !== "ERR_SERVER_NOT_RUNNING") { | ||
throw e; | ||
@@ -182,0 +182,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const httpError_1 = require("./httpError"); | ||
const httpError_1 = require("./errors/httpError"); | ||
const _ = require("lodash"); | ||
class ErrorHandler { | ||
@@ -8,4 +9,4 @@ static handleError(e, res) { | ||
res.statusCode = ErrorHandler.getStatusCode(err); | ||
let options = res.req.app.options; | ||
let msg = ErrorHandler.getErrorMessage(err, res.statusCode, options.errorStack, options.errorMessage); | ||
//let options = res.req.app.options; | ||
let msg = ErrorHandler.getErrorMessage(err, res.statusCode); | ||
res.send(msg); | ||
@@ -22,13 +23,20 @@ } | ||
} | ||
static getErrorMessage(e, statusCode, errorStack, errorMessage) { | ||
if (e instanceof httpError_1.HttpError && e.data) { | ||
return e.data; | ||
static getErrorMessage(e, statusCode) { | ||
let dto = { | ||
statusCode: statusCode, | ||
message: e.toString() | ||
}; | ||
if (e instanceof httpError_1.HttpError) { | ||
if (_.isPlainObject(e.data)) { | ||
_.extend(dto, e.data); | ||
} | ||
dto.message = e.message; | ||
if (e.code) { | ||
dto.code = e.code; | ||
} | ||
if (e.error) { | ||
dto.error = e.error.toString(); | ||
} | ||
} | ||
if (statusCode == 500 && errorStack) { | ||
return e.stack; | ||
} | ||
if (e.toString && errorMessage) { | ||
return e.toString(); | ||
} | ||
return statusCode.toString(); | ||
return dto; | ||
} | ||
@@ -35,0 +43,0 @@ } |
import {IResponse} from "./response"; | ||
import {HttpError} from "./httpError"; | ||
import {HttpError} from "./errors/httpError"; | ||
import _ = require("lodash"); | ||
@@ -11,5 +12,5 @@ export class ErrorHandler { | ||
let options = res.req.app.options; | ||
//let options = res.req.app.options; | ||
let msg = ErrorHandler.getErrorMessage(err, res.statusCode, options.errorStack, options.errorMessage); | ||
let msg = ErrorHandler.getErrorMessage(err, res.statusCode); | ||
@@ -32,19 +33,29 @@ res.send(msg); | ||
private static getErrorMessage(e: Error | HttpError, statusCode: number, errorStack: boolean, errorMessage: boolean): string { | ||
private static getErrorMessage(e: Error | HttpError, statusCode: number): any { | ||
if (e instanceof HttpError && e.data) { | ||
return e.data; | ||
} | ||
let dto: any = { | ||
statusCode: statusCode, | ||
message: e.toString() | ||
}; | ||
if (statusCode == 500 && errorStack) { | ||
return e.stack; | ||
} | ||
if (e instanceof HttpError) { | ||
if (e.toString && errorMessage) { | ||
return e.toString(); | ||
if (_.isPlainObject(e.data)) { | ||
_.extend(dto, e.data) | ||
} | ||
dto.message = e.message; | ||
if (e.code) { | ||
dto.code = e.code | ||
} | ||
if (e.error) { | ||
dto.error = e.error.toString() | ||
} | ||
} | ||
return statusCode.toString(); | ||
return dto | ||
} | ||
} |
@@ -26,2 +26,3 @@ "use strict"; | ||
proto.render = function (path, params) { | ||
this.sending = true; | ||
if (arguments.length == 1 && typeof path !== "string") { | ||
@@ -115,2 +116,3 @@ params = path; | ||
proto.send = function (data) { | ||
this.sending = true; | ||
//check if need to gzip | ||
@@ -117,0 +119,0 @@ if (this.useGzip) { |
@@ -22,2 +22,3 @@ import http = require('http'); | ||
useGzip: boolean; | ||
sending: boolean | ||
@@ -71,2 +72,5 @@ status(code: number): IResponse | ||
proto.render = function (path: string | string[], params?: any): Promise<void> { | ||
this.sending = true; | ||
if (arguments.length == 1 && typeof path !== "string") { | ||
@@ -190,2 +194,4 @@ params = path; | ||
proto.send = function (data?: string | Buffer) { | ||
this.sending = true; | ||
//check if need to gzip | ||
@@ -192,0 +198,0 @@ if (this.useGzip) { |
@@ -5,3 +5,3 @@ "use strict"; | ||
const appolo_cache_1 = require("appolo-cache"); | ||
const httpError_1 = require("./httpError"); | ||
const httpError_1 = require("./errors/httpError"); | ||
const fs = require("fs"); | ||
@@ -8,0 +8,0 @@ const path = require("path"); |
import {Cache} from "appolo-cache"; | ||
import {IOptions} from "./IOptions"; | ||
import {HttpError} from "./httpError"; | ||
import {HttpError} from "./errors/httpError"; | ||
import {IResponse} from "./response"; | ||
@@ -5,0 +5,0 @@ import fs = require("fs"); |
@@ -7,3 +7,3 @@ { | ||
"server", | ||
"rocket" | ||
"appolo" | ||
], | ||
@@ -23,3 +23,3 @@ "author": { | ||
"main": "./index.js", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"license": "MIT", | ||
@@ -26,0 +26,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65552
47
1235