Browse Source

refactor(neon): Cleanup NeonError

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/852/head
jld3103 1 year ago
parent
commit
07791ce7db
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 86
      packages/neon/neon/lib/src/widgets/error.dart

86
packages/neon/neon/lib/src/widgets/error.dart

@ -112,59 +112,47 @@ class NeonError extends StatelessWidget {
@internal @internal
static NeonExceptionDetails getDetails(final dynamic error) { static NeonExceptionDetails getDetails(final dynamic error) {
if (error is String) { switch (error) {
return NeonExceptionDetails( case String():
getText: (final _) => error,
);
}
if (error is NeonException) {
return error.details;
}
if (error is DynamiteApiException) {
if (error.statusCode == 401) {
return NeonExceptionDetails( return NeonExceptionDetails(
getText: (final context) => AppLocalizations.of(context).errorCredentialsForAccountNoLongerMatch, getText: (final _) => error,
isUnauthorized: true,
); );
} case NeonException():
return error.details;
if (error.statusCode >= 500 && error.statusCode <= 599) { case DynamiteApiException():
if (error.statusCode == 401) {
return NeonExceptionDetails(
getText: (final context) => AppLocalizations.of(context).errorCredentialsForAccountNoLongerMatch,
isUnauthorized: true,
);
}
if (error.statusCode >= 500 && error.statusCode <= 599) {
return NeonExceptionDetails(
getText: (final context) => AppLocalizations.of(context).errorServerHadAProblemProcessingYourRequest,
);
}
case SocketException():
return NeonExceptionDetails( return NeonExceptionDetails(
getText: (final context) => AppLocalizations.of(context).errorServerHadAProblemProcessingYourRequest, getText: (final context) => error.address != null
? AppLocalizations.of(context).errorUnableToReachServerAt(error.address!.host)
: AppLocalizations.of(context).errorUnableToReachServer,
);
case ClientException():
return NeonExceptionDetails(
getText: (final context) => error.uri != null
? AppLocalizations.of(context).errorUnableToReachServerAt(error.uri!.host)
: AppLocalizations.of(context).errorUnableToReachServer,
);
case HttpException():
return NeonExceptionDetails(
getText: (final context) => error.uri != null
? AppLocalizations.of(context).errorUnableToReachServerAt(error.uri!.host)
: AppLocalizations.of(context).errorUnableToReachServer,
);
case TimeoutException():
return NeonExceptionDetails(
getText: (final context) => AppLocalizations.of(context).errorConnectionTimedOut,
); );
}
}
if (error is SocketException) {
return NeonExceptionDetails(
getText: (final context) => error.address != null
? AppLocalizations.of(context).errorUnableToReachServerAt(error.address!.host)
: AppLocalizations.of(context).errorUnableToReachServer,
);
}
if (error is ClientException) {
return NeonExceptionDetails(
getText: (final context) => error.uri != null
? AppLocalizations.of(context).errorUnableToReachServerAt(error.uri!.host)
: AppLocalizations.of(context).errorUnableToReachServer,
);
}
if (error is HttpException) {
return NeonExceptionDetails(
getText: (final context) => error.uri != null
? AppLocalizations.of(context).errorUnableToReachServerAt(error.uri!.host)
: AppLocalizations.of(context).errorUnableToReachServer,
);
}
if (error is TimeoutException) {
return NeonExceptionDetails(
getText: (final context) => AppLocalizations.of(context).errorConnectionTimedOut,
);
} }
return NeonExceptionDetails( return NeonExceptionDetails(

Loading…
Cancel
Save