- added error logging;

This commit is contained in:
Vitalii Kiiko
2024-11-29 15:50:53 +01:00
parent a18b03a13d
commit ca78d4992b
3 changed files with 58 additions and 20 deletions

View File

@@ -9,6 +9,7 @@
"@emailjs/browser": "^4.4.1",
"@emotion/styled": "11.13.0",
"@number-flow/react": "0.2.0",
"@sentry/browser": "^8.41.0",
"@tanstack/react-table": "^8.20.5",
"@wordpress/i18n": "5.8.0",
"@wordpress/react-i18n": "4.8.0",

View File

@@ -16,13 +16,9 @@ import ApplicationService from '../../../../service/application-service';
import { FilterMatchMode, FilterOperator } from 'primereact/api';
import { DataTable } from 'primereact/datatable';
import { Column } from 'primereact/column';
import { InputText } from 'primereact/inputtext';
import { IconField } from 'primereact/iconfield';
import { InputIcon } from 'primereact/inputicon';
import { Dropdown } from 'primereact/dropdown';
import { ProgressBar } from 'primereact/progressbar';
import { Button } from 'primereact/button';
//import { Calendar } from 'primereact/calendar';
import { Tag } from 'primereact/tag';
import ProperBandoLabel from '../../../../components/ProperBandoLabel';
import { Link } from 'react-router-dom';

View File

@@ -1,9 +1,33 @@
import { storeGet } from '../store';
import * as Sentry from "@sentry/browser";
export class NetworkService {
static TOKEN_KEY
static REFRESH_TOKEN_KEY
static logApiError = (endpoint, status = 0, resp) => {
try {
if ([500].includes(status)) {
Sentry.init({
dsn: "https://e7b2134f7d816f663bb83e51b106a694@o4508381921738752.ingest.de.sentry.io/4508381935501392",
environment: process.env.NODE_ENV || "development"
});
const error = new Error(`Status ${status}`);
Sentry.captureException(`Error in endpoint: ${endpoint}`, {
level: 'error',
extra: {
originalError: error,
details: resp
}
});
}
} catch (err) {
console.log(err);
}
}
static postEmptyResponse = (url, body, callback, errorCallback) => {
fetch(url, {
method: 'POST',
@@ -77,10 +101,12 @@ export class NetworkService {
return { response: await response.json(), status: status }
})
.then(data => {
if (data.status >= 400 && data.status <= 599)
if (data.status >= 400 && data.status <= 599) {
errorCallback(data.response)
else
this.logApiError(url, data.status, data.response);
} else {
callback(data.response)
}
})
.catch(err => errorCallback(err));
};
@@ -118,10 +144,12 @@ export class NetworkService {
return { response: await response.json(), status: status }
})
.then(data => {
if (data.status >= 400 && data.status <= 599)
if (data.status >= 400 && data.status <= 599) {
errorCallback(data.response)
else
this.logApiError(url, data.status, data.response);
} else {
callback(data.response)
}
})
.catch(err => errorCallback(err));
};
@@ -159,10 +187,12 @@ export class NetworkService {
return { response: await response.blob(), status: status }
})
.then(data => {
if (data.status >= 400 && data.status <= 599)
if (data.status >= 400 && data.status <= 599) {
errorCallback(data.response)
else
this.logApiError(url, data.status, data.response);
} else {
callback(data.response)
}
})
.catch(err => errorCallback(err));
};
@@ -198,10 +228,12 @@ export class NetworkService {
return { response: await response.json(), status: status }
})
.then(data => {
if (data.status >= 400 && data.status <= 599)
if (data.status >= 400 && data.status <= 599) {
errorCallback(data.response)
else
this.logApiError(url, data.status, data.response);
} else {
callback(data.response)
}
})
.catch(err => errorCallback(err));
};
@@ -261,10 +293,12 @@ export class NetworkService {
return { response: await response.json(), status: status }
})
.then(data => {
if (data.status >= 400 && data.status <= 599)
if (data.status >= 400 && data.status <= 599) {
errorCallback(data.response)
else
this.logApiError(url, data.status, data.response);
} else {
callback(data.response)
}
})
.catch(err => errorCallback(err));
};
@@ -381,12 +415,15 @@ export class NetworkService {
})
.then(data => {
if (data.status >= 400 && data.status <= 599) {
errorCallback(data.response)
errorCallback(data.response);
this.logApiError(url, data.status, data.response);
} else {
callback(data.response)
}
})
.catch(err => errorCallback(err));
.catch(err => {
errorCallback(err)
});
};
@@ -422,10 +459,12 @@ export class NetworkService {
return { response: await response.blob(), status: status }
})
.then(data => {
if (data.status >= 400 && data.status <= 599)
if (data.status >= 400 && data.status <= 599) {
errorCallback(data.response)
else
this.logApiError(url, data.status, data.response);
} else {
callback(data.response)
}
})
.catch(err => errorCallback(err));
};
@@ -504,10 +543,12 @@ export class NetworkService {
return { response: await response.json(), status: status }
})
.then(data => {
if (data.status >= 400 && data.status <= 599)
if (data.status >= 400 && data.status <= 599) {
errorCallback(data.response)
else
this.logApiError(url, data.status, data.response);
} else {
callback(data.response)
}
})
.catch(err => errorCallback(err));