Skip to content

Commit

Permalink
chore: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nozomi-koborinai committed Jan 26, 2025
1 parent 6c1595e commit e35fb37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/data/app_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AppException implements Exception {
final String message;
const AppException([this.message = 'エラーが発生しました']);

@override
String toString() {
return message;
}
}
10 changes: 7 additions & 3 deletions lib/data/genkit_client.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:dio/dio.dart';
import 'package:flutter_gakkai_07/data/app_exception.dart';
import 'package:flutter_gakkai_07/data/genkit_response.dart';

class GenkitClient {
Expand Down Expand Up @@ -38,12 +39,15 @@ class GenkitClient {
);

if (response.statusCode != 200) {
throw Exception('Failed to generate image: ${response.statusCode}');
throw AppException(errorMessage);
}

return GenkitResponse.fromJson(response.data);
} on DioException catch (e) {
throw Exception('Failed to generate image: ${e.message}');
} catch (e) {
throw AppException(errorMessage);
}
}

final errorMessage = '''Imagen3 による画像生成に失敗しました。
再度、キャラクター生成をお試しください。''';
}

0 comments on commit e35fb37

Please sign in to comment.