Closed wisnuwiry closed 2 years ago
I believe that the errorBuilder
has all of the information that it can provide. Can you provide a minimal repro so that I can track it down?
hey @csells , I believe he is talking about custom exceptions, currently is just returning a generic exception Exception
with a description message.
https://github.com/csells/go_router/search?q=throw
Maybe would be a good idea to implement custom exceptions like @wisnuwiry mentioned, otherwise we have to parse the message and try to understand what kind of exception is in order to display an error page.
Custom exceptions should come through just fine. Do you have a sample where they don't?
Custom exceptions should come through just fine. Do you have a sample where they don't?
Hey Chris, when we have any exception related to navigation, do we receive a Custom Exception with some kind of type? or it's just a Generic Exception (Exception class) with the error details?
I think @wisnuwiry is talking about my last question.
Sorry, @csells @diegoveloper I was busy earlier,
As an example of implementing a custom exception such as the dio plugin as below:
And if implemented in go_router it might be like this:
abstract class GoRouterException implements Exception {
const GoRouterException({
required this.message,
this.details,
});
final String message;
final Object? details;
}
class GoRouterNotFoundException extends GoRouterException {
const GoRouterNotFoundException({
required String message,
Object? details,
}) : super(
message: message,
details: details,
);
}
// And add some exceptions according to the error type in `go_router`.
...
// in go_router_state.dart
/// The route state during routing.
class GoRouterState {
....
// Update `Exception` to custom exception `GoRouterException`
/// The error associated with this sub-route.
final GoRouterException? error;
...
}
...
// And when in errorBuilder I can check that the error occurred because of what and the type can be specific based on the error type of the exception:
final _router = GoRouter(
...
errorBuilder: (context, state) {
if(state.error is GoRouterNotFoundException){
return NotFoundPage(state.error?.message);
}
return DefaultErrorPage(state.error);
}
);
This is more or less what I wanted, thanks for responding 🙏
Description
When an error occurs when navigation eg the route does not exist or eg, queryParameter or params is invalid, or also problems about the assertion can be distinguished when in
errorBuilder
.So when the error handle in
errorBuilder
I can render a specific page according to the error type.Currently
For the current version I only get exception info when there is an error when navigating, and I don't know what type of exception it is and what the error is
Expected
The following might help an example of implementing an error handle: