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. 28
      packages/neon/neon/lib/src/widgets/error.dart

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

@ -112,56 +112,44 @@ class NeonError extends StatelessWidget {
@internal
static NeonExceptionDetails getDetails(final dynamic error) {
if (error is String) {
switch (error) {
case String():
return NeonExceptionDetails(
getText: (final _) => error,
);
}
if (error is NeonException) {
case NeonException():
return error.details;
}
if (error is DynamiteApiException) {
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,
);
}
}
if (error is SocketException) {
case SocketException():
return NeonExceptionDetails(
getText: (final context) => error.address != null
? AppLocalizations.of(context).errorUnableToReachServerAt(error.address!.host)
: AppLocalizations.of(context).errorUnableToReachServer,
);
}
if (error is ClientException) {
case ClientException():
return NeonExceptionDetails(
getText: (final context) => error.uri != null
? AppLocalizations.of(context).errorUnableToReachServerAt(error.uri!.host)
: AppLocalizations.of(context).errorUnableToReachServer,
);
}
if (error is HttpException) {
case HttpException():
return NeonExceptionDetails(
getText: (final context) => error.uri != null
? AppLocalizations.of(context).errorUnableToReachServerAt(error.uri!.host)
: AppLocalizations.of(context).errorUnableToReachServer,
);
}
if (error is TimeoutException) {
case TimeoutException():
return NeonExceptionDetails(
getText: (final context) => AppLocalizations.of(context).errorConnectionTimedOut,
);

Loading…
Cancel
Save