fixes checkEmail error

This commit is contained in:
mohammad
2024-12-29 11:22:11 +03:00
parent c834ad0670
commit 8f7b46be25

View File

@ -76,7 +76,9 @@ class UserPermissionApi {
} }
} }
Future<String?> checkEmail(email) async {
Future<String?> checkEmail(String email) async {
try { try {
final response = await _httpService.post( final response = await _httpService.post(
path: ApiEndpoints.checkEmail, path: ApiEndpoints.checkEmail,
@ -84,16 +86,26 @@ class UserPermissionApi {
body: {"email": email}, body: {"email": email},
expectedResponseModel: (json) { expectedResponseModel: (json) {
if (json['statusCode'] != 400) { 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) { } on DioException catch (e) {
if (e.response != null) { if (e.response != null) {
print(e.response?.data['error']);
final errorMessage = 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) { } catch (e) {
return e.toString(); return e.toString();
} }