Skip to content

Commit

Permalink
Feat: implement error formatting before showing to extract more details
Browse files Browse the repository at this point in the history
  • Loading branch information
mateussouzaweb committed Feb 11, 2024
1 parent 714329e commit 9590c77
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("<br/>")
}

/**
* Run application login process
* @param username
Expand Down Expand Up @@ -763,6 +773,7 @@ const getTextLanguages = () => {
export const App = {
getTemplate,
getImage,
formatError,
login,
logout,
isLoggedIn,
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const listResults: Callback = async ({ state, render }) => {
await render({
loaded: true,
error: true,
message: error.message
message: App.formatError(error)
})

}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const listHistory: Callback = async ({ state, render }) => {
await render({
loaded: true,
error: true,
message: error.message
message: App.formatError(error)
})

}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const listResults: Callback = async ({ state, render }) => {
await render({
loaded: true,
error: true,
message: error.message
message: App.formatError(error)
})

}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const makeLogin: Callback = async ({ element, render }) => {
Route.redirect('/home')
} catch (error) {
await render({
message: error.message
message: App.formatError(error)
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const listResults: Callback = async ({ state, render }) => {
await render({
loaded: true,
error: true,
message: error.message
message: App.formatError(error)
})

}
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/serie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -211,7 +211,7 @@ const listEpisodes: Callback = async ({ state, render }) => {
await render({
loaded: true,
error: true,
message: error.message
message: App.formatError(error)
})

}
Expand Down
5 changes: 3 additions & 2 deletions src/scripts/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/watchlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const listWatchlist: Callback = async ({ state, render }) => {
await render({
loaded: true,
error: true,
message: error.message
message: App.formatError(error)
})

}
Expand Down

0 comments on commit 9590c77

Please sign in to comment.