Merge branch '5368-tryErrors'
gitea/printnatura/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2023-04-26 13:49:51 +02:00
commit c6bd546fb9
3 changed files with 304 additions and 288 deletions

View File

@ -28,6 +28,8 @@ concurrency: 4
reconnectTimeout: 10
refreshRate: 1000
tmpDir: /dev/shm/printnatura
retryAttempts: 3
retryTimeout: 1000
db:
host: localhost
port: 3306
@ -44,7 +46,6 @@ salix:
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

@ -7,6 +7,8 @@ concurrency: 4
reconnectTimeout: 10
refreshRate: 1000
tmpDir: /dev/shm/printnatura
retryAttempts: 3
retryTimeout: 1500
db:
host: localhost
port: 3306

View File

@ -240,7 +240,7 @@ class PrintServer {
// Request
let pdfData;
for (let attempts = 0; !pdfData && attempts < 2; attempts++) {
for (let attempts = 0; !pdfData && attempts < this.conf.retryAttempts; attempts++) {
try {
const res = await this.api({
method: 'get',
@ -251,15 +251,28 @@ class PrintServer {
pdfData = res.data;
}
catch (err) {
if (err.name === 'AxiosError' && err.code === 'ERR_BAD_REQUEST') {
if (err.name === 'AxiosError' && attempts < this.conf.retryAttempts - 1) {
const res = err.response;
if (res.status === 401) { // Unauthorized
switch(res.status) {
case 401: // Unauthorized
await this.getToken();
} else {
break;
case 502 || 504: // Bad Gateway & Gateway Timeout
await new Promise(
resolve => setTimeout(resolve, this.conf.retryTimeout));
break;
default:
try {
if (err.code === 'ERR_BAD_REQUEST') {
const resMessage = JSON.parse(res.data).error.message;
const resErr = new Error(`${err.message}: ${resMessage}`);
resErr.stack = err.stack;
throw resErr;
} else
throw err;
} catch (err) {
throw err;
}
}
} else
throw err;