mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
framework: add default error log
This commit is contained in:
1 file changed
+2
@@ -247,6 +247,7 @@ export class Handler<C = CordisContext> extends HandlerCommon<C> {
|
|||||||
|
|
||||||
async onerror(error: HydroError) {
|
async onerror(error: HydroError) {
|
||||||
error.msg ||= () => error.message;
|
error.msg ||= () => error.message;
|
||||||
|
console.error(`Error on user request: ${error.msg()}\n`, error);
|
||||||
if (error instanceof UserFacingError && !process.env.DEV) error.stack = '';
|
if (error instanceof UserFacingError && !process.env.DEV) error.stack = '';
|
||||||
this.response.status = error instanceof UserFacingError ? error.code : 500;
|
this.response.status = error instanceof UserFacingError ? error.code : 500;
|
||||||
this.response.template = error instanceof UserFacingError ? 'error.html' : 'bsod.html';
|
this.response.template = error instanceof UserFacingError ? 'error.html' : 'bsod.html';
|
||||||
@@ -286,6 +287,7 @@ export class ConnectionHandler<C> extends HandlerCommon<C> {
|
|||||||
|
|
||||||
onerror(err: HydroError) {
|
onerror(err: HydroError) {
|
||||||
if (err instanceof UserFacingError) err.stack = this.request.path;
|
if (err instanceof UserFacingError) err.stack = this.request.path;
|
||||||
|
else console.error('Error on user websocket:', err);
|
||||||
this.send({
|
this.send({
|
||||||
error: {
|
error: {
|
||||||
name: err.name,
|
name: err.name,
|
||||||
|
|||||||
Reference in new issue
Block a user