Correctly forwarding HTTP error status code from admin to front
This commit is contained in:
parent
a5aa9b6cf9
commit
48c3f951bf
3 changed files with 18 additions and 13 deletions
|
@ -60,10 +60,7 @@ export class AuthenticateController extends BaseController {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("An error happened", e)
|
this.errorToResponse(e, res);
|
||||||
res.writeStatus(e.status || "500 Internal Server Error");
|
|
||||||
this.addCorsHeaders(res);
|
|
||||||
res.end('An error happened');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,4 +8,20 @@ export class BaseController {
|
||||||
res.writeHeader('access-control-allow-methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
res.writeHeader('access-control-allow-methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
||||||
res.writeHeader('access-control-allow-origin', '*');
|
res.writeHeader('access-control-allow-origin', '*');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns any exception into a HTTP response (and logs the error)
|
||||||
|
*/
|
||||||
|
protected errorToResponse(e: any, res: HttpResponse): void {
|
||||||
|
console.error("An error happened", e);
|
||||||
|
if (e.response) {
|
||||||
|
res.writeStatus(e.response.status+" "+e.response.statusText);
|
||||||
|
this.addCorsHeaders(res);
|
||||||
|
res.end("An error occurred: "+e.response.status+" "+e.response.statusText);
|
||||||
|
} else {
|
||||||
|
res.writeStatus("500 Internal Server Error")
|
||||||
|
this.addCorsHeaders(res);
|
||||||
|
res.end("An error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,15 +59,7 @@ export class MapController extends BaseController{
|
||||||
this.addCorsHeaders(res);
|
this.addCorsHeaders(res);
|
||||||
res.end(JSON.stringify(mapDetails));
|
res.end(JSON.stringify(mapDetails));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.response) {
|
this.errorToResponse(e, res);
|
||||||
res.writeStatus(e.response.status+" "+e.response.statusText);
|
|
||||||
this.addCorsHeaders(res);
|
|
||||||
res.end("An error occurred: "+e.response.status+" "+e.response.statusText);
|
|
||||||
} else {
|
|
||||||
res.writeStatus("500 Internal Server Error")
|
|
||||||
this.addCorsHeaders(res);
|
|
||||||
res.end("An error occurred");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue