Slight improvement to error handlers in frontend

This commit is contained in:
Bobby Wibowo 2020-11-04 11:26:22 +07:00
parent 762ef3141c
commit a0ab3d436e
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
4 changed files with 29 additions and 6 deletions

View File

@ -44,7 +44,7 @@ page.onAxiosError = error => {
const statusText = cloudflareErrors[error.response.status] || error.response.statusText const statusText = 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
: 'There was an error with the request, please check the console for more information.' : 'There was an error with the request.\nPlease check the console for more information.'
return swal(`${error.response.status} ${statusText}`, description, 'error') return swal(`${error.response.status} ${statusText}`, description, 'error')
} }

View File

@ -112,7 +112,10 @@ page.onError = error => {
console.error(error) console.error(error)
const content = document.createElement('div') const content = document.createElement('div')
content.innerHTML = `<code>${error.toString()}</code>` content.innerHTML = `
<p><code>${error.toString()}</code></p>
<p>Please check your console for more information.</p>
`
return swal({ return swal({
title: 'An error occurred!', title: 'An error occurred!',
icon: 'error', icon: 'error',
@ -140,7 +143,7 @@ page.onAxiosError = error => {
const statusText = cloudflareErrors[error.response.status] || error.response.statusText const statusText = 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
: 'There was an error with the request, please check the console for more information.' : 'There was an error with the request.\nPlease check the console for more information.'
return swal(`${error.response.status} ${statusText}`, description, 'error') return swal(`${error.response.status} ${statusText}`, description, 'error')
} }

View File

@ -90,7 +90,10 @@ page.onError = error => {
console.error(error) console.error(error)
const content = document.createElement('div') const content = document.createElement('div')
content.innerHTML = `<code>${error.toString()}</code>` content.innerHTML = `
<p><code>${error.toString()}</code></p>
<p>Please check your console for more information.</p>
`
return swal({ return swal({
title: 'An error occurred!', title: 'An error occurred!',
icon: 'error', icon: 'error',
@ -120,7 +123,7 @@ page.onAxiosError = (error, cont) => {
if (!cont) { if (!cont) {
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
: 'There was an error with the request, please check the console for more information.' : 'There was an error with the request.\nPlease check the console for more information.'
return swal(`${error.response.status} ${statusText}`, description, 'error') return swal(`${error.response.status} ${statusText}`, description, 'error')
} else if (error.response.data && error.response.data.description) { } else if (error.response.data && error.response.data.description) {
return error.response return error.response

View File

@ -21,6 +21,22 @@ const page = {
// Disable video.js telemetry (should already be disabled by default since v7 though) // Disable video.js telemetry (should already be disabled by default since v7 though)
window.HELP_IMPROVE_VIDEOJS = false window.HELP_IMPROVE_VIDEOJS = false
// 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 => {
// Better Cloudflare errors // Better Cloudflare errors
@ -125,7 +141,8 @@ page.reloadVideo = () => {
page.toggleReloadBtn(true) page.toggleReloadBtn(true)
}).catch(error => { }).catch(error => {
page.toggleReloadBtn(true) page.toggleReloadBtn(true)
page.onAxiosError(error) if (typeof error.response !== 'undefined') page.onAxiosError(error)
else page.onError(error)
}) })
} }