diff --git a/lib/screens/camera_analysis_mixin.dart b/lib/screens/camera_analysis_mixin.dart index d9c39fe..b957da3 100644 --- a/lib/screens/camera_analysis_mixin.dart +++ b/lib/screens/camera_analysis_mixin.dart @@ -381,9 +381,10 @@ mixin CameraAnalysisMixin on ConsumerState } debugPrint('Analysis error: $e'); + final errDetail = _extractErrorCode(e.toString()); messenger.showSnackBar( SnackBar( - content: const Text('解析に失敗しました。時間をおいて再試行してください。'), + content: Text('解析に失敗しました。時間をおいて再試行してください。$errDetail'), duration: const Duration(seconds: 5), backgroundColor: appColors.error, ), @@ -395,6 +396,23 @@ mixin CameraAnalysisMixin on ConsumerState } } + /// エラー文字列から HTTP ステータスコードや既知キーワードを抽出して表示用の短い補足を返す。 + /// ユーザーが画面を見たときに「どのエラーか」を把握できるようにするため。 + String _extractErrorCode(String err) { + final patterns = { + RegExp(r'\b(4\d{2}|5\d{2})\b'): (Match m) => ' [${m.group(0)}]', + RegExp(r'API_KEY_INVALID|PERMISSION_DENIED'): (_) => ' [key?]', + RegExp(r'RESOURCE_EXHAUSTED'): (_) => ' [quota]', + RegExp(r'NOT_FOUND'): (_) => ' [model?]', + RegExp(r'timeout', caseSensitive: false): (_) => ' [timeout]', + }; + for (final entry in patterns.entries) { + final m = entry.key.firstMatch(err); + if (m != null) return entry.value(m); + } + return ''; + } + /// さけのわ自動マッチング処理 /// /// 登録後にバックグラウンドで実行。 diff --git a/lib/services/gemini_service.dart b/lib/services/gemini_service.dart index 067f786..3324475 100644 --- a/lib/services/gemini_service.dart +++ b/lib/services/gemini_service.dart @@ -484,7 +484,7 @@ name・brand を出力する直前に以下を確認してください: } const primaryModel = 'gemini-2.5-flash'; - const fallbackModel = 'gemini-2.0-flash'; + const fallbackModel = 'gemini-2.5-flash-lite'; final promptText = customPrompt ?? _mainAnalysisPrompt; diff --git a/pubspec.yaml b/pubspec.yaml index 9513065..ad73af8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.48+55 +version: 1.0.49+56 environment: sdk: ^3.10.1