diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 8016a5a..f48d7bc 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -29,6 +29,16 @@ const getImage = (images: any[]) => { return image } +/** + * Format error for better visualization + * @param error + * @returns + */ +const formatError = (error: Error) => { + const message = error.message + "\n\n" + error.stack; + return message.split("\n").join("
") +} + /** * Run application login process * @param username @@ -763,6 +773,7 @@ const getTextLanguages = () => { export const App = { getTemplate, getImage, + formatError, login, logout, isLoggedIn, diff --git a/src/scripts/explore.ts b/src/scripts/explore.ts index 099832d..d2dc8e7 100644 --- a/src/scripts/explore.ts +++ b/src/scripts/explore.ts @@ -152,7 +152,7 @@ const listResults: Callback = async ({ state, render }) => { await render({ loaded: true, error: true, - message: error.message + message: App.formatError(error) }) } diff --git a/src/scripts/history.ts b/src/scripts/history.ts index a0c7f6b..8297986 100644 --- a/src/scripts/history.ts +++ b/src/scripts/history.ts @@ -77,7 +77,7 @@ const listHistory: Callback = async ({ state, render }) => { await render({ loaded: true, error: true, - message: error.message + message: App.formatError(error) }) } diff --git a/src/scripts/home.ts b/src/scripts/home.ts index a271c12..3162488 100644 --- a/src/scripts/home.ts +++ b/src/scripts/home.ts @@ -130,7 +130,7 @@ const listResults: Callback = async ({ state, render }) => { await render({ loaded: true, error: true, - message: error.message + message: App.formatError(error) }) } diff --git a/src/scripts/login.ts b/src/scripts/login.ts index ef27e09..255267b 100644 --- a/src/scripts/login.ts +++ b/src/scripts/login.ts @@ -27,7 +27,7 @@ const makeLogin: Callback = async ({ element, render }) => { Route.redirect('/home') } catch (error) { await render({ - message: error.message + message: App.formatError(error) }) } diff --git a/src/scripts/search.ts b/src/scripts/search.ts index 4498998..691ebb4 100644 --- a/src/scripts/search.ts +++ b/src/scripts/search.ts @@ -109,7 +109,7 @@ const listResults: Callback = async ({ state, render }) => { await render({ loaded: true, error: true, - message: error.message + message: App.formatError(error) }) } diff --git a/src/scripts/serie.ts b/src/scripts/serie.ts index af2ba3d..9754fea 100644 --- a/src/scripts/serie.ts +++ b/src/scripts/serie.ts @@ -142,7 +142,7 @@ const listSerieInfo: Callback = async ({ state }) => { } catch (error) { state.error = true - state.message = error.message + state.message = App.formatError(error) } fire('loading::hide') @@ -211,7 +211,7 @@ const listEpisodes: Callback = async ({ state, render }) => { await render({ loaded: true, error: true, - message: error.message + message: App.formatError(error) }) } diff --git a/src/scripts/video.ts b/src/scripts/video.ts index 314bc51..c280de0 100644 --- a/src/scripts/video.ts +++ b/src/scripts/video.ts @@ -314,7 +314,8 @@ const playVideo: Callback = async (component) => { try { await video.play() - } catch (err) { + } catch (error) { + console.log(error.message) } area.classList.remove('video-is-paused') @@ -758,7 +759,7 @@ const onRender: Callback = async (component) => { trigger(element, 'click', '.video-play') } catch (error) { - showError(error.message) + showError(App.formatError(error)) } fire('loading::hide') diff --git a/src/scripts/watchlist.ts b/src/scripts/watchlist.ts index 1233cf7..b9d8e6a 100644 --- a/src/scripts/watchlist.ts +++ b/src/scripts/watchlist.ts @@ -77,7 +77,7 @@ const listWatchlist: Callback = async ({ state, render }) => { await render({ loaded: true, error: true, - message: error.message + message: App.formatError(error) }) }