feat(auth): enhance login error handling with detailed error code mapping
All checks were successful
Frontend CI / ota-android (push) Successful in 1m29s
Frontend CI / build-and-push-web (push) Successful in 2m31s
Frontend CI / build-android-apk (push) Successful in 36m5s

- Add backend error_code support (INVALID_CREDENTIALS, USER_BANNED, etc.)
- Improve network error detection with code=0 fallback
- Add granular HTTP status code handling (400, 401, 403, 429, 5xx)
- Update LoginScreen to display authStore error or generic message
- Include notification service improvements:
  - Keep JPush connection alive in background via setKeepLongConnInBackground
  - Add manual sound/vibration for local notifications via preferences
- Fix SearchScreen layout by accounting for floating tab bar and safe area
This commit is contained in:
lafay
2026-04-28 17:25:27 +08:00
parent cf9feeae68
commit d2120a257d
5 changed files with 98 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
import { Platform, NativeModules, AppState } from 'react-native';
import { Platform, NativeModules, AppState, Vibration } from 'react-native';
import { pushService } from './pushService';
import * as Notifications from 'expo-notifications';
import { getNotificationPreferencesSync } from './notificationPreferences';
@@ -112,6 +112,9 @@ class JPushService {
// Register listeners only once (idempotent guard)
this._registerListeners();
// 退后台保持极光长连接,确保推送实时到达
this._setBackgroundKeepLongConn(true);
// 初始化 SDK
JPush!.init({
appKey: jpushAppKey,
@@ -165,12 +168,12 @@ class JPushService {
console.warn('[JPush] setChannelAndSound failed:', error);
}
// Ensure notification channel has sound & vibration enabled via expo-notifications
try {
Notifications.setNotificationChannelAsync('jpush_notification', {
name: '推送通知',
importance: Notifications.AndroidImportance.HIGH,
vibrationPattern: [0, 250, 250, 250],
sound: 'default',
enableLights: true,
showBadge: true,
});
@@ -179,6 +182,30 @@ class JPushService {
}
}
/**
* 设置退后台是否保持极光长连接
* @see https://docs.jiguang.cn/jpush/client/Android/android_api#退后台是否保持极光长连接-api
*/
private _setBackgroundKeepLongConn(keep: boolean): void {
if (!JPush) return;
try {
if (Platform.OS === 'android') {
const jpushModule = NativeModules.JPushModule;
if (jpushModule?.setKeepLongConnInBackground) {
jpushModule.setKeepLongConnInBackground(keep);
console.log('[JPush] setKeepLongConnInBackground:', keep);
} else {
console.warn('[JPush] setKeepLongConnInBackground not available in native module');
}
} else if (Platform.OS === 'ios') {
JPush.setBackgroundEnable(keep);
console.log('[JPush] setBackgroundEnable:', keep);
}
} catch (error) {
console.warn('[JPush] setBackgroundKeepLongConn failed:', error);
}
}
private _fetchRegistrationID(): void {
if (!JPush) return;
JPush.getRegistrationID((result: any) => {
@@ -329,6 +356,21 @@ class JPushService {
} else {
JPush.addLocalNotification(params);
}
// JPush local notification does not support sound/vibration directly.
// Trigger them manually based on user preferences.
const prefs = getNotificationPreferencesSync();
if (prefs.soundEnabled) {
// Play system default notification sound via a silent expo-notification
Notifications.scheduleNotificationAsync({
content: { title: '', body: '', sound: true, vibrate: [] },
trigger: null,
}).catch(() => {});
}
if (prefs.vibrationEnabled) {
// Use React Native Vibration API for device-level vibration
Vibration.vibrate([0, 250, 250, 250]);
}
} catch (error) {
console.error('[JPush] addLocalNotification failed:', error);
}

View File

@@ -208,9 +208,6 @@ class SystemNotificationService {
async clearAllNotifications(): Promise<void> {
jpushService.clearAllNotifications();
if (Platform.OS === 'web' && 'Notification' in window) {
// No programmatic way to clear browser notifications
}
}
async clearBadge(): Promise<void> {