Its not working anymore on last express verison
Closed this issue · 1 comments
GuilhermeLessa commented
When it throws, the express server instance crash on console:
express 4.18.2
app.use((
err: any,
req: any,
res: any,
next: any
) => {
let statusCode: number = 500;
let message: string = 'Internal Server Error';
if (err.message) {
message = err.message;
}
if (err instanceof ApiError) {
statusCode = err.statusCode;
}
res.status(statusCode).send({ message });
return;
});
app.get("/farms",
query('hiveApiToken').trim().notEmpty(),
async (req: any, res: any, next: any) => {
const validation = validationResult(req);
if (!validation.isEmpty()) {
next(new ApiError('Unauthorized', 401));
return;
}
const { hiveApiToken } = req.query;
let response;
try {
response = await hiveOs.getFarms(hiveApiToken);
} catch (error: any) {
next(error);
return;
}
const farms = response.data.data.map((farm: any) => ({
id: farm.id,
name: farm.name,
}));
res.send(farms);
});
GuilhermeLessa commented
Sorry my bad, I didn't saw my promise wrapper without reject handle