Skip to content

Commit 8aee60c

Browse files
authored
Merge pull request #1829 from appwrite/fix-1827-flutter-oauth-error-callback
fix(flutter): surface OAuth failure errors from callback URL
2 parents d502a13 + 5c1f7aa commit 8aee60c

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

templates/flutter/lib/src/client_io.dart.twig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:convert';
12
import 'dart:io';
23
import 'dart:math';
34
import 'package:cookie_jar/cookie_jar.dart';
@@ -427,6 +428,29 @@ class ClientIO extends ClientBase with ClientMixin {
427428
final key = url.queryParameters['key'];
428429
final secret = url.queryParameters['secret'];
429430
if (key == null || secret == null) {
431+
final error = url.queryParameters['error'];
432+
if (error != null && error.isNotEmpty) {
433+
try {
434+
final parsed = jsonDecode(error);
435+
if (parsed is Map) {
436+
final codeValue = parsed['code'];
437+
final int? code = codeValue is int
438+
? codeValue
439+
: int.tryParse('${codeValue ?? ''}');
440+
throw {{spec.info.title | caseUcfirst}}Exception(
441+
parsed['message']?.toString() ?? error,
442+
code,
443+
parsed['type']?.toString(),
444+
error,
445+
);
446+
}
447+
} on {{spec.info.title | caseUcfirst}}Exception {
448+
rethrow;
449+
} catch (_) {
450+
// Fall through to a plain-string error when JSON is malformed.
451+
}
452+
throw {{spec.info.title | caseUcfirst}}Exception(error);
453+
}
430454
throw {{spec.info.title | caseUcfirst}}Exception(
431455
"Invalid OAuth2 Response. Key and Secret not available.",
432456
500,

0 commit comments

Comments
 (0)