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