feat : login api call
This commit is contained in:
53
packages/auth/lib/data/common/dio_error_handler.dart
Normal file
53
packages/auth/lib/data/common/dio_error_handler.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
class DioErrorHandler {
|
||||
void handle(DioException error) {
|
||||
switch (error.response?.statusCode) {
|
||||
case 401:
|
||||
_handle401();
|
||||
break;
|
||||
case 403:
|
||||
_handle403();
|
||||
break;
|
||||
default:
|
||||
_handleGeneric(error);
|
||||
}
|
||||
}
|
||||
|
||||
//wrong password/user name => "detail": "No active account found with the given credentials" - 401
|
||||
void _handle401() {
|
||||
Get.showSnackbar(
|
||||
_errorSnackBar('نام کاربری یا رمز عبور اشتباه است'),
|
||||
);
|
||||
}
|
||||
|
||||
//wrong captcha => "detail": "Captcha code is incorrect" - 403
|
||||
void _handle403() {
|
||||
Get.showSnackbar(
|
||||
_errorSnackBar('کد امنیتی اشتباه است'),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleGeneric(DioException error) {
|
||||
// General error handling
|
||||
}
|
||||
|
||||
GetSnackBar _errorSnackBar(String message) {
|
||||
return GetSnackBar(
|
||||
titleText: Text(
|
||||
'خطا',
|
||||
style: AppFonts.yekan14.copyWith(color: Colors.white),
|
||||
),
|
||||
messageText: Text(
|
||||
message,
|
||||
style: AppFonts.yekan12.copyWith(color: Colors.white),
|
||||
),
|
||||
backgroundColor: AppColor.error,
|
||||
margin: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
borderRadius: 12,
|
||||
duration: Duration(milliseconds: 3500),
|
||||
snackPosition: SnackPosition.TOP,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user