Skip to content

Instantly share code, notes, and snippets.

@vijayinyoutube
Created June 4, 2022 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijayinyoutube/469b3b412b98462aa8fe3ee3fc34f9aa to your computer and use it in GitHub Desktop.
Save vijayinyoutube/469b3b412b98462aa8fe3ee3fc34f9aa to your computer and use it in GitHub Desktop.
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