handelException method

Exceptions handelException()

Implementation

Exceptions handelException() {
  if (response?.statusCode == 422) {
    if ((response?.data["message"] as String?)?.contains("phone") ?? false) {
      return const Exceptions.phoneInvalid();
    } else if ((response?.data["message"] as String?)?.contains("email") ??
        false) {
      return const Exceptions.emailInvalide();
    }
    return const Exceptions.invalidInput();
  }

  if (response?.statusCode == 401) {
    return const Exceptions.unAuthorized();
  }

  if (error is SocketException) {
    return const Exceptions.network();
  }

  if (type == DioExceptionType.connectionTimeout ||
      type == DioExceptionType.sendTimeout) {
    return const Exceptions.network();
  }

  return const Exceptions.other();
}