Skip to content

Instantly share code, notes, and snippets.

@Kaperskyguru
Last active July 20, 2020 12:55
Show Gist options
  • Save Kaperskyguru/69c2e8463d2c846faa21f2d0e7069834 to your computer and use it in GitHub Desktop.
Save Kaperskyguru/69c2e8463d2c846faa21f2d0e7069834 to your computer and use it in GitHub Desktop.
import Swal from "sweetalert2";
import "sweetalert2/dist/sweetalert2.min.css";
export default class ErrorService {
constructor() {
// this.initHandler();
}
static onError(error) {
const response = error.response;
if (response && response.status >= 400 && response.status < 405) {
// You can handle this differently
ErrorService.sentryLogEngine(error);
return false;
}
// Send Error to Log Engine e.g LogRocket
ErrorService.logRocketLogEngine(error);
}
static onWarn(error) {
// Send Error to Log Engine e.g LogRocket
this.logRocketLogEngine(error);
}
static onInfo(error) {
// You can handle this differently
this.sentryLogEngine(error);
}
static onDebug(error) {
const response = error.response;
if (response && response.status >= 400 && response.status < 405) {
// You can handle this differently
this.sentryLogEngine(error);
return false;
}
// Send Error to Log Engine e.g LogRocket
this.logRocketLogEngine(error);
}
static initHandler() {
const scope = this;
window.onerror = (message, url, lineNo, columnNo, error) => {
console.log(error, "test");
if (error) {
scope.onError(error);
console.log(message, url, lineNo, columnNo, error);
}
};
}
static displayErrorAlert(message) {
Swal.fire({
title: "Error!",
text: message,
icon: "error",
});
}
static logRocketLogEngine(error) {
// Implement LogRocket Engine here
console.log(error, "LogRocket");
}
static sentryLogEngine(error) {
// Implement Sentry Engine here
console.log(error, "Sentry");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment