@alterior/core
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -23,2 +23,7 @@ import { Provider } from '@angular/core'; | ||
/** | ||
* Hide exception information from 500 responses (should be set for production). | ||
* Defaults to off (ie, exception information is included) | ||
*/ | ||
hideExceptions?: boolean; | ||
/** | ||
* Port to serve HTTP on. Defaults to 3000. | ||
@@ -25,0 +30,0 @@ */ |
@@ -29,2 +29,8 @@ import { Provider } from '@angular/core'; | ||
/** | ||
* Hide exception information from 500 responses (should be set for production). | ||
* Defaults to off (ie, exception information is included) | ||
*/ | ||
hideExceptions? : boolean; | ||
/** | ||
* Port to serve HTTP on. Defaults to 3000. | ||
@@ -31,0 +37,0 @@ */ |
@@ -44,2 +44,3 @@ "use strict"; | ||
var silent = appOptions.silent; | ||
var hideExceptions = appOptions.hideExceptions || false; | ||
(appOptions.providers || []) | ||
@@ -211,6 +212,10 @@ .filter(function (x) { return !x['then']; }) | ||
else { | ||
res.status(500).send(JSON.stringify({ | ||
message: 'Failed to resolve this resource.', | ||
error: e | ||
})); | ||
console.error("Exception while handling route " + route.path + " via method " + controller.name + "." + route.method + "():"); | ||
console.error(e); | ||
var response = { | ||
message: 'An exception occurred while handling this request.' | ||
}; | ||
if (!hideExceptions) | ||
response.error = e.toString !== Object.prototype.toString ? e.toString() : e; | ||
res.status(500).send(JSON.stringify(response)); | ||
} | ||
@@ -217,0 +222,0 @@ } |
@@ -56,2 +56,3 @@ import 'reflect-metadata'; | ||
let silent = appOptions.silent; | ||
let hideExceptions = appOptions.hideExceptions || false; | ||
@@ -260,6 +261,12 @@ (appOptions.providers || []) | ||
} else { | ||
res.status(500).send(JSON.stringify({ | ||
message: 'Failed to resolve this resource.', | ||
error: e | ||
})); | ||
console.error(`Exception while handling route ${route.path} via method ${controller.name}.${route.method}():`); | ||
console.error(e); | ||
let response : any = { | ||
message: 'An exception occurred while handling this request.' | ||
}; | ||
if (!hideExceptions) | ||
response.error = e.toString !== Object.prototype.toString ? e.toString() : e; | ||
res.status(500).send(JSON.stringify(response)); | ||
} | ||
@@ -266,0 +273,0 @@ } |
{ | ||
"name": "@alterior/core", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "An Express-based Typescript MVC framework using decorators and Angular 2 dependency injection.", |
@@ -245,2 +245,28 @@ # Alterior | ||
## Uncaught Exceptions | ||
When an exception occurs while executing a controller route method (excluding HttpExceptions), Alterior will respond | ||
with an HTTP 500 error. By default, exception information will be included with the response. If the caught exception | ||
has a `toString()` method, it will be executed and its return value will be sent. If it does not, the error object will | ||
be included directly, being converted along with the rest of the response to JSON. | ||
`throw new Error('This is the error text')` would produce: | ||
``` | ||
{"message":"An exception occurred while handling this request.","error":"Error: This is the error text | ||
at FooController.sampleRequest (music.js:36:29)"} | ||
``` | ||
`throw { foo: 'bar' }` would product: | ||
``` | ||
{"message":"An exception occurred while handling this request.","error":{"foo":"bar"}} | ||
``` | ||
You can disable the inclusion of exception information in responses (and this is recommended for production). | ||
To do so, set `AppOptions.hideExceptions` to `true`. The `error` field will then be excluded from 500 responses. | ||
``` | ||
{"message":"An exception occurred while handling this request."} | ||
``` | ||
## MongoDB integration | ||
@@ -247,0 +273,0 @@ |
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
179675
2448
321