Skip to content
Discussion options

You must be logged in to vote

Technically, yeah, all you want is to avoid catching the thrown exception, cuz that'd "block" the redirect attempt.

I think though, it does sound like a good idea to decouple the try/catch handling block from the redirect logic.

For example here, if getData throws - then you handle the errors, log and what not, and then separately decide what to do in terms of the UI.

let data = null

try {
  data = await getData();
} catch(reason) {
  handleReasonForDataFailure(reason)
  logErrors(reason)
}

if (!data) {
  redirect()
}

Cuz otherwise, you likely need to have duplicated redirect calls. For example, if getData is fetch based, it might itself not throw on 404's etc..

let data = null

try {
  d…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sijunnoh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants