Created
June 4, 2022 17:50
-
-
Save vijayinyoutube/469b3b412b98462aa8fe3ee3fc34f9aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:io'; | |
class ExceptionHandlers { | |
getExceptionString(error) { | |
if (error is SocketException) { | |
return 'No internet connection.'; | |
} else if (error is HttpException) { | |
return 'HTTP error occured.'; | |
} else if (error is FormatException) { | |
return 'Invalid data format.'; | |
} else if (error is TimeoutException) { | |
return 'Request timedout.'; | |
} else if (error is BadRequestException) { | |
return error.message.toString(); | |
} else if (error is UnAuthorizedException) { | |
return error.message.toString(); | |
} else if (error is NotFoundException) { | |
return error.message.toString(); | |
} else if (error is FetchDataException) { | |
return error.message.toString(); | |
} else { | |
return 'Unknown error occured.'; | |
} | |
} | |
} | |
class AppException implements Exception { | |
final String? message; | |
final String? prefix; | |
final String? url; | |
AppException([this.message, this.prefix, this.url]); | |
} | |
class BadRequestException extends AppException { | |
BadRequestException([String? message, String? url]) | |
: super(message, 'Bad request', url); | |
} | |
class FetchDataException extends AppException { | |
FetchDataException([String? message, String? url]) | |
: super(message, 'Unable to process the request', url); | |
} | |
class ApiNotRespondingException extends AppException { | |
ApiNotRespondingException([String? message, String? url]) | |
: super(message, 'Api not responding', url); | |
} | |
class UnAuthorizedException extends AppException { | |
UnAuthorizedException([String? message, String? url]) | |
: super(message, 'Unauthorized request', url); | |
} | |
class NotFoundException extends AppException { | |
NotFoundException([String? message, String? url]) | |
: super(message, 'Page not found', url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment