refactor: refs #6555 wip: improve error handler
gitea/worker-time-control/pipeline/pr-test This commit looks good Details

This commit is contained in:
jorgep 2024-06-14 15:57:23 +02:00
parent 9d323bdb21
commit d2b5e1fc76
1 changed files with 5 additions and 10 deletions

View File

@ -68,7 +68,6 @@ async function call(url, { method = "GET", body = {}, params = {} }) {
const controller = new AbortController(); const controller = new AbortController();
const { signal } = controller; const { signal } = controller;
const timeoutId = setTimeout(() => controller.abort(), 2000); const timeoutId = setTimeout(() => controller.abort(), 2000);
let mensaje;
const opts = { const opts = {
method, method,
headers: { headers: {
@ -86,6 +85,8 @@ async function call(url, { method = "GET", body = {}, params = {} }) {
clearTimeout(timeoutId); clearTimeout(timeoutId);
return res; return res;
} catch (e) { } catch (e) {
let mensaje = "Ha ocurrido un error, consulta con informática";
switch (e.name) { switch (e.name) {
case "SyntaxError": case "SyntaxError":
mensaje = "Requested JSON parse failed"; mensaje = "Requested JSON parse failed";
@ -99,7 +100,7 @@ async function call(url, { method = "GET", body = {}, params = {} }) {
case "UserError": case "UserError":
mensaje = e.message; mensaje = e.message;
break; break;
case "error": default:
switch (e.code) { switch (e.code) {
case 0: case 0:
mensaje = "Not connect: Verify Network"; mensaje = "Not connect: Verify Network";
@ -108,17 +109,11 @@ async function call(url, { method = "GET", body = {}, params = {} }) {
mensaje = "No se ha podido conectar con Salix, consulta con informática"; mensaje = "No se ha podido conectar con Salix, consulta con informática";
break; break;
case 555: case 555:
mensaje = e.message; mensaje = "Error 555";
break;
case e.code >= 400 && e.code < 500:
mensaje = e.name;
break; break;
default: default:
mensaje = "Ha ocurrido un error, consulta con informática"; if (e.status >= 400 && e.status < 500) mensaje = e.message;
} }
break;
default:
mensaje = "Ha ocurrido un error, consulta con informática";
} }
printError(mensaje); printError(mensaje);
} }