GigyaError.fromPlatformException constructor

GigyaError.fromPlatformException(
  1. PlatformException exception
)

Construct a GigyaError from the given exception.

Implementation

factory GigyaError.fromPlatformException(PlatformException exception) {
  final Object? details = exception.details;

  if (details is! Map<Object?, Object?>) {
    return const GigyaError();
  }

  // Remove the specific error details, to avoid including them twice.
  final int? apiVersion = details.remove('apiVersion') as int?;
  final String? callId = details.remove('callId') as String?;
  final int? errorCode = details.remove('errorCode') as int?;
  final String? errorMessage = details.remove('errorMessage') as String? ??
      details.remove('errorDetails') as String?;

  return GigyaError(
    apiVersion: apiVersion,
    callId: callId,
    details: details.cast<String, Object?>(),
    errorCode: errorCode,
    errorMessage: errorMessage,
  );
}