|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +import '../../Presentation/Components/snack_bar.dart'; |
| 4 | + |
| 5 | +enum ExceptionTypes { |
| 6 | + socketException, |
| 7 | + httpException, |
| 8 | + formatException, |
| 9 | + timeoutException |
| 10 | +} |
| 11 | + |
| 12 | +class ExceptionHandlers { |
| 13 | + String typeOfException(ExceptionTypes exceptionTypes) { |
| 14 | + switch (exceptionTypes) { |
| 15 | + case ExceptionTypes.socketException: |
| 16 | + return 'No internet connection.'; |
| 17 | + case ExceptionTypes.httpException: |
| 18 | + return 'HTTP error occured.'; |
| 19 | + case ExceptionTypes.formatException: |
| 20 | + return 'Invalid data format.'; |
| 21 | + case ExceptionTypes.timeoutException: |
| 22 | + return 'Request timeout.'; |
| 23 | + } |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +class AppException implements Exception { |
| 28 | + final String? message; |
| 29 | + final String? prefix; |
| 30 | + final String? url; |
| 31 | + |
| 32 | + AppException([this.message, this.prefix, this.url]); |
| 33 | +} |
| 34 | + |
| 35 | +class BadRequestException extends AppException { |
| 36 | + BadRequestException([String? message, String? url]) |
| 37 | + : super(message, 'Bad request', url); |
| 38 | +} |
| 39 | + |
| 40 | +class FetchDataException extends AppException { |
| 41 | + FetchDataException([String? message, String? url]) |
| 42 | + : super(message, 'Unable to process the request', url); |
| 43 | +} |
| 44 | + |
| 45 | +class ApiNotRespondingException extends AppException { |
| 46 | + ApiNotRespondingException([String? message, String? url]) |
| 47 | + : super(message, 'Api not responding', url); |
| 48 | +} |
| 49 | + |
| 50 | +class UnAuthorizedException extends AppException { |
| 51 | + UnAuthorizedException([String? message, String? url]) |
| 52 | + : super(message, 'Unauthorized request', url); |
| 53 | +} |
| 54 | + |
| 55 | +class NotFoundException extends AppException { |
| 56 | + NotFoundException([String? message, String? url]) |
| 57 | + : super(message, 'Page not found', url); |
| 58 | +} |
| 59 | + |
0 commit comments