diff --git a/lib/services/user_permission.dart b/lib/services/user_permission.dart index d5cb8243..91e45073 100644 --- a/lib/services/user_permission.dart +++ b/lib/services/user_permission.dart @@ -76,7 +76,9 @@ class UserPermissionApi { } } - Future checkEmail(email) async { + + + Future checkEmail(String email) async { try { final response = await _httpService.post( path: ApiEndpoints.checkEmail, @@ -84,16 +86,26 @@ class UserPermissionApi { body: {"email": email}, expectedResponseModel: (json) { if (json['statusCode'] != 400) { - return json["message"]; + var message = json["message"]; + if (message is String) { + return message; + } else { + return 'Unexpected message format'; + } } + return null; }, ); - return response ?? []; + return response ?? 'Unknown error occurred'; } on DioException catch (e) { if (e.response != null) { + print(e.response?.data['error']); final errorMessage = e.response?.data['error']; - return errorMessage; + return errorMessage is String + ? errorMessage + : 'Error occurred while checking email'; } + return 'Error occurred while checking email'; } catch (e) { return e.toString(); }