GQLException.fromException constructor
GQLException.fromException(
- dynamic exception, {
- List<
GQLExceptionParser> ? exceptionParsers,
Implementation
factory GQLException.fromException(
dynamic exception, {
List<GQLExceptionParser>? exceptionParsers,
}) {
// Project-level parsers
if (exceptionParsers != null) {
for (final parser in exceptionParsers) {
final result = parser.parse(exception);
if (result != null) return result;
}
}
// Built-in paths
if (exception is Exception) {
if (exception is OperationException) {
if (exception.graphqlErrors.isNotEmpty) {
final graphqlError = exception.graphqlErrors[0];
final errorMessage = graphqlError.message;
final errorCode = graphqlError.extensions?['code'] ?? 'NO_CODE';
final extensions = graphqlError.extensions;
return AppError(
AppErrorModel(
message: errorMessage,
code: errorCode,
extensions: extensions,
),
);
}
return AppError(AppErrorModel(message: 'Unknown GraphQL error'));
} else if (exception is GQLException) {
return exception;
} else {
return const UnExpectedError();
}
} else {
if (exception is String && exception.contains('is not a subtype of')) {
return const UnableToProcessError();
}
return const UnExpectedError();
}
}