question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unclear error handling

See original GitHub issue

Is your feature request related to a problem? Please describe. I’m learning Fritz2, and I’m making a login form. When user enters bad credentials, and the API returns HTTP 401, I’d like to show the error (toast). I can’t find a way how.

Another related issue is in Tracker. When I start the remote request, and it fails, the button keeps spinning and I couldn’t find any method how to stop it.

Describe the solution you’d like

  • Make special chapter in documentation about error handling.
  • Demonstrate it in remotes example.
    • I have uBlock, which blocks the request to the domain you use in this example. I see the error in developer console, but nothing in the UI.

Abouty the tyracker problem, I’d suggest to change the track method like this:

// OLD (0.10.1)
return operation().also { state.value = null } 

// NEW
return try { operation() } finally { state.value = null }

Describe alternatives you’ve considered I couldn’t find any. Just provide some documentation and example.

Additional context My handler looks like this. If you could show me how to display the error toast, I’d be grateful.

val login = handle { model ->
    loading.track {
        if (validator.isValid(model, Unit)) {
            try {
                http("/apiIs2/authUser")
                    .acceptJson()
                    .contentType("application/json")
                    .body(
                        JSON.stringify(
                            json(
                                "username" to model.login, "password" to model.password
                            )
                        )
                    )
                    .post()
                    .getBody()
                router.navTo("main")
            } catch (t: Throwable) {
                console.log(t)
                toast { // NOT DISPLAYED :(
                    content {
                        alert {
                            title("Login error")
                            content(
                                if (t is FetchException && t.statusCode == 401.toShort()) {
                                    "Bad credentials"
                                } else {
                                    "$t"
                                }
                            )
                        }
                    }
                }
            }
        }
        model
    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
chausknechtcommented, Jun 9, 2021

Ok, I have to correct myself: Of course it is quite easy to make track safe for unsafe operations.

I already provided PR #430 to improve this situation!

1reaction
EvaBScommented, Jun 9, 2021

I display my errors like this:

// my serverErrorStore is of type <MyMessage?>, you could use ComponentValidationMessage or whatever else fits your usecase

// in RenderContext, render all server messages in the same place in app. 
// you could also make this store a list for multiple messages 
serverErrorStore.render { message ->
    if (message != null) {
        showToast {
            content {
                alert { content( //... message content) }
            }
        }
    }
}

// in REST-Handler in Store when error occurs:
serverErrorStore.update(thisErrorMessageWhichOccurredJustNow)

// clear store when you're done with the error, I do that when I enter a handler or new page content is rendered
serverErrorStore.update(null)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Messages: Examples, Best Practices & Common Mistakes
1. Write for humans (be understandable) · 2. Make sure the message is helpful · 3. Use a touch of humor · 4....
Read more >
How to Write Good Error Messages - UX Planet
1. Be Clear And Not Ambiguous ... Write error message in clear and simple language. User should be able to understand the problem...
Read more >
Best 10 Examples And Guidelines For Error Messages
Here are ten basic guidelines to help you create the most effective error messaging for your users. Click here to see all of...
Read more >
Unclear behavior at specific error handling - Stack Overflow
I'm trying to handle specific errors but I'm surprised about the behavior. ... it returns true , even if err is nil ....
Read more >
How to Write Good Error Messages - UX Design World
If the error message is ambiguous and the user is not able to find the reason for the message, then it is of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found