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

Loading…
Cancel
Save