refs #5368 Added error try 502 & 504
gitea/printnatura/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2023-03-07 19:08:06 +01:00
parent 3755f0fe03
commit 292866bcf9
2 changed files with 16 additions and 10 deletions

View File

@ -37,7 +37,6 @@ refreshRate: 1000
Exec
```
> docker run --name printnatura -it --rm -v $PWD/config.local.yml:/printnatura/config.local.yml:ro -v $PWD/cupsd.conf:/etc/cups/cupsd.conf:ro -p 80:631 printnatura
```
Bash

View File

@ -239,7 +239,7 @@ class PrintServer {
// Request
let pdfData;
for (let attempts = 0; !pdfData && attempts < 2; attempts++) {
for (let attempts = 0; !pdfData && attempts < 3; attempts++) {
try {
const res = await this.api({
method: 'get',
@ -250,21 +250,28 @@ class PrintServer {
pdfData = res.data;
}
catch (err) {
if (err.name === 'AxiosError' && err.code === 'ERR_BAD_REQUEST') {
if (err.name === 'AxiosError') {
const res = err.response;
if (res.status === 401) { // Unauthorized
await this.getToken();
} else {
const resMessage = JSON.parse(res.data).error.message;
const resErr = new Error(`${err.message}: ${resMessage}`);
resErr.stack = err.stack;
throw resErr;
switch(res.status) {
case 401: // Unauthorized
await this.getToken();
break;
case 502 || 504: // Bad Gateway & Gateway Timeout
break;
default:
const resMessage = JSON.parse(res.data).error.message;
const resErr = new Error(`${err.message}: ${resMessage}`);
resErr.stack = err.stack;
throw resErr;
}
} else
throw err;
}
}
if (!pdfData)
throw 'Could not get pdf from server'
// Save PDF to disk
const printer = jobData.printer;
const tmpPath = conf.tmpDir;