ApiException class

Custom exception class for handling API-related errors.

This class uses freezed to create immutable error types with predefined error messages. Each factory constructor represents a specific type of API error that can occur during network operations.

Example:

try {
  // API call
} catch (e) {
  if (e is ApiException) {
    switch (e) {
      case _ServerError():
        // Handle server error
      case _NetworkError():
        // Handle network connectivity error
      // ... handle other cases
    }
  }
}
Implemented types
Annotations
  • @freezed

Constructors

ApiException.network({@Default.new('Please make sure about your connection !') String msg})
Creates a network error instance for connectivity issues.
const
factory
ApiException.notFound({@Default.new('Something went wrong ! Please try again later ') String msg})
Creates a not found error instance, typically used for 404 status codes.
const
factory
ApiException.server({@Default.new('Server went wrong ! Please try again later ') String msg})
Creates a server error instance, typically used for 500 status codes.
const
factory
ApiException.unknown({@Default.new('Something went wrong ! Please try again later ') String msg})
Creates an unknown error instance for unhandled error cases.
const
factory

Properties

copyWith → $ApiExceptionCopyWith<ApiException>
Create a copy of ApiException with the given fields replaced by the non-null parameter values.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
msg String
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

map<TResult extends Object?>({required TResult server(_ServerError value), required TResult notFound(_NotFoundError value), required TResult network(_NetworkError value), required TResult unknown(_UnKnownError value)}) → TResult
inherited
mapOrNull<TResult extends Object?>({TResult? server(_ServerError value)?, TResult? notFound(_NotFoundError value)?, TResult? network(_NetworkError value)?, TResult? unknown(_UnKnownError value)?}) → TResult?
inherited
maybeMap<TResult extends Object?>({TResult server(_ServerError value)?, TResult notFound(_NotFoundError value)?, TResult network(_NetworkError value)?, TResult unknown(_UnKnownError value)?, required TResult orElse()}) → TResult
inherited
maybeWhen<TResult extends Object?>({TResult server(String msg)?, TResult notFound(String msg)?, TResult network(String msg)?, TResult unknown(String msg)?, required TResult orElse()}) → TResult
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
when<TResult extends Object?>({required TResult server(String msg), required TResult notFound(String msg), required TResult network(String msg), required TResult unknown(String msg)}) → TResult
inherited
whenOrNull<TResult extends Object?>({TResult? server(String msg)?, TResult? notFound(String msg)?, TResult? network(String msg)?, TResult? unknown(String msg)?}) → TResult?
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited