Parcourir la source

Standard HttpStatusException Handling in webserver.class.ts

Christian Kahlau il y a 3 ans
Parent
commit
c7ddad5f64
1 fichiers modifiés avec 3 ajouts et 0 suppressions
  1. 3 0
      src/webserver.class.ts

+ 3 - 0
src/webserver.class.ts

@@ -8,6 +8,7 @@ import { PrivateHandler } from './handlers/private-handler.class';
 import { PublicHandler } from './handlers/public-handler.class';
 
 import { AuthenticationException } from './model/err/authentication.exception';
+import { HttpStatusException } from './model/err/http-status.exception';
 
 const multipartMiddleware = multiparty();
 
@@ -67,6 +68,8 @@ export class Webserver {
         try {
           if (err instanceof AuthenticationException) {
             res.status(err.statusCode).send(err.statusText);
+          } else if (err instanceof HttpStatusException) {
+            res.status(err.statusCode).send(err.message);
           } else if (Object.keys(err).includes('code') && err.code === 'EBADCSRFTOKEN') {
             res.status(403).send(err.message);
           } else {