mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-09 23:15:46 +01:00
🐛 Fix ping issue
This commit is contained in:
@@ -16,12 +16,17 @@ export const appRouter = createTRPCRouter({
|
||||
const configName = getCookie('config-name');
|
||||
const config = getConfig(configName?.toString() ?? 'default');
|
||||
const app = config.apps.find((app) => app.id === input);
|
||||
|
||||
const errorResponse = {
|
||||
state: 'offline',
|
||||
status: 500,
|
||||
statusText: 'Check logs for more informations',
|
||||
};
|
||||
|
||||
const url = app?.url;
|
||||
if (url === undefined || !app) {
|
||||
throw new TRPCError({
|
||||
code: 'NOT_FOUND',
|
||||
message: 'App or url not found',
|
||||
});
|
||||
Consola.error(`App ${input} not found`);
|
||||
return errorResponse;
|
||||
}
|
||||
const res = await axios
|
||||
.get(url, { httpsAgent: agent, timeout: 2000 })
|
||||
@@ -31,27 +36,20 @@ export const appRouter = createTRPCRouter({
|
||||
}))
|
||||
.catch((error: AxiosError) => {
|
||||
if (error.response) {
|
||||
if (getIsOk(app as AppType, error.response.status)) {
|
||||
return {
|
||||
state: 'offline',
|
||||
status: error.response.status,
|
||||
statusText: error.response.statusText,
|
||||
};
|
||||
}
|
||||
return {
|
||||
state: getIsOk(app as AppType, error.response.status) ? 'online' : 'offline',
|
||||
status: error.response.status,
|
||||
statusText: error.response.statusText,
|
||||
};
|
||||
}
|
||||
|
||||
if (error.code === 'ECONNABORTED') {
|
||||
throw new TRPCError({
|
||||
code: 'TIMEOUT',
|
||||
message: 'Request Timeout',
|
||||
});
|
||||
Consola.error(`Ping timeout for ${input}`);
|
||||
return errorResponse;
|
||||
}
|
||||
|
||||
Consola.error(`Unexpected response: ${error.message}`);
|
||||
throw new TRPCError({
|
||||
code: 'INTERNAL_SERVER_ERROR',
|
||||
cause: app.id,
|
||||
message: error.message,
|
||||
});
|
||||
return errorResponse;
|
||||
});
|
||||
return res;
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user