backend: properly catch exception in controllers so that the server does not crash
This commit is contained in:
@@ -13,9 +13,9 @@ export default class AniListController {
|
||||
|
||||
const fromApiText = await fromApi.text();
|
||||
res.status(fromApi.status).send(fromApiText);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
next();
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ export class MangaUpdatesController {
|
||||
}
|
||||
|
||||
async search(req: Request, res: Response, next: NextFunction): Promise<void> {
|
||||
try {
|
||||
const bjson = req.body;
|
||||
if (bjson['stype'] !== 'title' || bjson['type'] !== 'Manga' || !bjson['search']?.trim().length) {
|
||||
res.status(400).send('Only {stype: "title", type: "Manga", search: "some title"} allowed!');
|
||||
@@ -46,9 +47,13 @@ export class MangaUpdatesController {
|
||||
|
||||
res.status(200).setHeader('Content-Type', 'application/json').send(fromApiJson);
|
||||
next('router');
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
}
|
||||
|
||||
async getById(req: Request, res: Response, next: NextFunction): Promise<void> {
|
||||
try {
|
||||
const id = req.params.id!.toLowerCase();
|
||||
|
||||
const fromCache = this.cache.getSeriesById(id);
|
||||
@@ -74,9 +79,13 @@ export class MangaUpdatesController {
|
||||
|
||||
res.status(200).setHeader('Content-Type', 'application/json').send(fromApiJson);
|
||||
next();
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
}
|
||||
|
||||
async getGroupById(req: Request, res: Response, next: NextFunction): Promise<void> {
|
||||
try {
|
||||
const id = req.params.id!.toLowerCase();
|
||||
|
||||
const fromCache = this.cache.getSeriesGroupsById(id);
|
||||
@@ -102,6 +111,9 @@ export class MangaUpdatesController {
|
||||
|
||||
res.status(200).setHeader('Content-Type', 'application/json').send(fromApiJson);
|
||||
next();
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
}
|
||||
|
||||
async getSeriesIdFromWebsiteId(req: Request, res: Response, next: NextFunction): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user