KindeError.fromError constructor
KindeError.fromError(
- Object error,
- StackTrace stackTrace
Implementation
factory KindeError.fromError(Object error, StackTrace stackTrace) {
if (error is KindeError) {
return error;
}
if (error is PlatformException) {
return _flutterAppAuthExceptionMapper(error);
}
if (error is AuthorizationException) {
return AuthorizationKindeError.fromOauth2Exception(error);
}
if (error is FormatException) {
if(error.message.contains("parameter \"state\" expected")) {
return KindeError(
code: KindeErrorCode.authStateNotMatch,
message: error.message);
}
final jsonMatch = RegExp(r'\{.*\}').firstMatch(error.message);
if (jsonMatch != null) {
final jsonString = jsonMatch.group(0);
try {
final jsonData = jsonDecode(jsonString!);
final error = jsonData['error'] as String?;
final errorDescription = jsonData['error_description'] as String?;
return KindeError(code: error ?? KindeErrorCode.unknown, message: errorDescription ?? 'Unknown error');
} catch (e) {
return KindeError(
code: KindeErrorCode.unknown, message: e.toString());
}
}
}
if (error is Exception) {
return _handleError(error);
}
return KindeError(message: error.toString(), stackTrace: stackTrace);
}