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 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 > 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 Bash

View File

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