mirror of
https://github.com/Viren070/AIOStreams.git
synced 2025-12-01 23:14:04 +01:00
fix(addon): properly handle errors safely
This commit is contained in:
@@ -7,7 +7,7 @@ export const errorResponse = (
|
||||
externalUrl?: string
|
||||
) => {
|
||||
return {
|
||||
streams: [errorStream(errorMessage, origin, path, externalUrl)],
|
||||
streams: [errorStream(errorMessage, 'Error', origin, path, externalUrl)],
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -63,6 +63,12 @@ app.use(express.json());
|
||||
// Built-in middleware for parsing URL-encoded data
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// unhandled errors
|
||||
app.use((err: any, req: Request, res: Response, next: any) => {
|
||||
console.error(`|ERR| server > ${err.message}`);
|
||||
res.status(500).send('Internal server error');
|
||||
});
|
||||
|
||||
app.use((req, res, next) => {
|
||||
res.append('Access-Control-Allow-Origin', '*');
|
||||
res.append('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
|
||||
@@ -219,9 +225,22 @@ app.get('/:config/stream/:type/:id.json', (req, res: Response): void => {
|
||||
req.ip;
|
||||
configJson.instanceCache = cache;
|
||||
const aioStreams = new AIOStreams(configJson);
|
||||
aioStreams.getStreams(streamRequest).then((streams) => {
|
||||
res.json({ streams: streams });
|
||||
});
|
||||
aioStreams
|
||||
.getStreams(streamRequest)
|
||||
.then((streams) => {
|
||||
res.json({ streams: streams });
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error(`|ERR| server > Internal addon error: ${error.message}`);
|
||||
res.json(
|
||||
errorResponse(
|
||||
'An unexpected error occurred, please check the logs or create an issue on GitHub',
|
||||
rootUrl(req),
|
||||
undefined,
|
||||
'https://github.com/Viren070/AIOStreams/issues/new?template=bug_report.yml'
|
||||
)
|
||||
);
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error(`|ERR| server > Internal addon error: ${error.message}`);
|
||||
res.json(
|
||||
|
||||
Reference in New Issue
Block a user