core/network/interceptors/ — Dio Interceptors

Manage authentication, error handling, and logging for Dio HTTP requests in Flutter.

Updated Apr 13, 2026
One-click install
npx skills add https://github.com/Vantoan252003/Mozi --skill core-network-interceptors-dio-interceptors
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: core/network/interceptors/ — Dio Interceptors
Source: https://github.com/Vantoan252003/Mozi/tree/main/lib/core/network/interceptors
Command: npx skills add https://github.com/Vantoan252003/Mozi --skill core-network-interceptors-dio-interceptors

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides standardized Dio interceptors to centralize authentication, error translation, and request/response logging for Flutter apps, reducing duplicated network handling and improving reliability.

Core Features & Use Cases

  • Auth Interceptor: Attaches Bearer tokens to requests and coordinates a single concurrent token refresh with a retry queue for failed 401 requests.
  • Error Interceptor: Maps DioException types and HTTP status codes into app-level typed exceptions such as UnauthorizedException, TimeoutException, NotFoundException, BadRequestException, and ServerException.
  • Logging Interceptor: Emits request/response/error logs only in debug builds using kDebugMode to avoid leaking information in production.
  • Use Case: Integrate these interceptors in a Flutter client to transparently handle token expiry, provide consistent error semantics to data sources, and keep production logs silent.

Quick Start

Implement AuthInterceptor, ErrorInterceptor, and LoggingInterceptor as described to attach bearer tokens, perform a single token refresh with a queued retry mechanism on 401 responses, and map Dio exceptions to typed app errors while logging only in debug builds.

Frequently Asked Questions about core/network/interceptors/ — Dio Interceptors

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle automatic token refresh and retry queued requests on 401 in Flutter Dio?

To handle token refresh in Flutter Dio, use a dedicated interceptor that coordinates a single concurrent refresh on 401 responses and queues failed requests to retry automatically once the new bearer token is retrieved.

How do I map DioException types to typed app-level exceptions in Flutter?

To map DioException types in Flutter, apply an error interceptor that translates HTTP status codes and exception types into typed app-level exceptions like UnauthorizedException, TimeoutException, NotFoundException, BadRequestException, and ServerException.

What is the best way to disable HTTP request logging in Flutter release builds using Dio?

To disable HTTP logging in Flutter release builds, use an interceptor that conditionally emits request, response, and error logs only when kDebugMode is true, keeping production logs completely silent.

How do I automatically attach Bearer tokens to HTTP requests in a Flutter Dio client?

To automatically attach Bearer tokens in a Flutter Dio client, implement an auth interceptor that injects the Authorization headers into outgoing requests transparently before they reach the network.

Can I use these Dio interceptors to centralize error handling and authentication for multiple Flutter network clients?

Yes, you can use these Dio interceptors to centralize authentication, error translation, and logging across multiple Flutter network clients, reducing duplicated network handling code and improving overall app reliability.