Merge branch '5368-tryErrors'
gitea/printnatura/pipeline/head This commit looks good
Details
gitea/printnatura/pipeline/head This commit looks good
Details
This commit is contained in:
commit
c6bd546fb9
|
@ -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
|
||||
|
|
|
@ -7,6 +7,8 @@ concurrency: 4
|
|||
reconnectTimeout: 10
|
||||
refreshRate: 1000
|
||||
tmpDir: /dev/shm/printnatura
|
||||
retryAttempts: 3
|
||||
retryTimeout: 1500
|
||||
db:
|
||||
host: localhost
|
||||
port: 3306
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue