fix: frontend errors handling

This commit is contained in:
Bobby Wibowo 2022-08-08 05:42:40 +07:00
parent 52299408ae
commit e0d0694a30
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
5 changed files with 36 additions and 0 deletions

View File

@ -37,8 +37,28 @@ page.unhide = () => {
if (floatingBtn) floatingBtn.classList.remove('is-hidden') if (floatingBtn) floatingBtn.classList.remove('is-hidden')
} }
// Handler for regular JS errors
page.onError = error => {
console.error(error)
const content = document.createElement('div')
content.innerHTML = `
<p><code>${error.toString()}</code></p>
<p>Please check your console for more information.</p>
`
return swal({
title: 'An error occurred!',
icon: 'error',
content
})
}
// Handler for Axios errors // Handler for Axios errors
page.onAxiosError = error => { page.onAxiosError = error => {
if (!error.response) {
return page.onError(error)
}
const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText
const description = error.response.data && error.response.data.description const description = error.response.data && error.response.data.description
? error.response.data.description ? error.response.data.description

View File

@ -147,6 +147,10 @@ page.onError = error => {
// Handler for Axios errors // Handler for Axios errors
page.onAxiosError = error => { page.onAxiosError = error => {
if (!error.response) {
return page.onError(error)
}
const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText
const description = error.response.data && error.response.data.description const description = error.response.data && error.response.data.description
? error.response.data.description ? error.response.data.description

View File

@ -55,6 +55,10 @@ page.onError = error => {
// Handler for Axios errors // Handler for Axios errors
page.onAxiosError = error => { page.onAxiosError = error => {
if (!error.response) {
return page.onError(error)
}
const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText
const description = error.response.data && error.response.data.description const description = error.response.data && error.response.data.description

View File

@ -118,6 +118,10 @@ page.onError = error => {
// Handler for Axios errors // Handler for Axios errors
page.onAxiosError = error => { page.onAxiosError = error => {
if (!error.response) {
return page.onError(error)
}
const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText
const description = error.response.data && error.response.data.description const description = error.response.data && error.response.data.description
? error.response.data.description ? error.response.data.description

View File

@ -51,6 +51,10 @@ page.onError = error => {
// Handler for Axios errors // Handler for Axios errors
page.onAxiosError = error => { page.onAxiosError = error => {
if (!error.response) {
return page.onError(error)
}
const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText
const description = error.response.data && error.response.data.description const description = error.response.data && error.response.data.description