UnauthorizedException class
Exception for HTTP 401 Unauthorized errors.
Thrown when authentication credentials are missing, invalid, or expired. This typically occurs when:
- Access token has expired
- User is not logged in
- Invalid credentials provided
The default message indicates session expiration and prompts re-authentication.
Handling this exception usually triggers a redirect to the login screen or automatic token refresh attempt.
Example:
if (response.statusCode == 401) {
throw UnauthorizedException(originalException: dioError);
// Interceptor will catch this and redirect to login
}
- Inheritance
-
- Object
- AppException
- NetworkAppException
- UnauthorizedException
Constructors
-
Creates an UnauthorizedException with an optional custom
message.const
Properties
- errorCode → String?
-
A machine-readable error code from the backend's
ErrorResponseenvelope (e.g.VALIDATION_ERROR,TOO_MANY_REQUESTS), ornullif the response body didn't match that schema.finalinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- message → String
-
A human-readable description of the error.
finalinherited
- originalException → DioException?
-
The underlying Dio exception that caused this network error.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- traceId → String?
-
The backend's request-trace identifier from the
ErrorResponseenvelope, for correlating this error with server-side logs — ornullif the response body didn't match that schema.finalinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
The string representation of this exception, including Dio-level details.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited