HttpStatusExtension extension
Extension on HttpStatus
to easily convert HTTP status codes into
corresponding HttpException instances, allowing for more descriptive and
granular error handling.
This extension provides a convenient way to handle different HTTP status codes by mapping them to specific exceptions. Each exception can carry additional details such as a human-readable explanation (detail), arbitrary data (data), and the URI (uri) associated with the HTTP request.
Example usage:
final httpStatus = HttpStatus.notFound;
try {
throw httpStatus.exception(detail: 'Resource not found', uri: Uri.parse('https://example.com'));
} on NotFoundHttpException catch (e) {
// Handle 404 Not Found exception
print(e.message);
}
- on
-
- HttpStatus
Methods
-
exception(
{String detail = '', Map< String, dynamic> ? data, Uri? uri}) → HttpException -
Creates an HttpException based on the
HttpStatus
value.