Skip to content

How to implement redirection inside Interceptor? #2395

Description

@bambinoua

I have a ValidationInterceptor which should force logout when some event is occurred.

How can I do this?

class ValidationInterceptor extends Interceptor {
  @override
  onError(DioException err, ErrorInterceptorHandler handler) {
    if(err.type == DioResponseType.badRequest && err.response!.statusCode == 401) {
      final logoutUri = Uri(path: '/logout');
      // ...
      // need to redirect to logout
      // ...
      handler.reject(err); // do I need this?
    } else {
      handler.next(err);
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    s: featureThis issue indicates a feature request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions