Skip to content

Commit 9d37d1e

Browse files
committed
fix exception and add exception test
1 parent 4a7f5ff commit 9d37d1e

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/SDK/Language/Dart.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ public function getFiles(): array
426426
'destination' => '/test/src/enums_test.dart',
427427
'template' => 'dart/test/src/enums_test.dart.twig',
428428
],
429+
[
430+
'scope' => 'default',
431+
'destination' => '/test/src/exception_test.dart',
432+
'template' => 'dart/test/src/exception_test.dart.twig',
433+
],
429434
[
430435
'scope' => 'default',
431436
'destination' => '/test/src/response_test.dart',

src/SDK/Language/Flutter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ public function getFiles(): array
280280
'destination' => '/test/src/enums_test.dart',
281281
'template' => 'dart/test/src/enums_test.dart.twig',
282282
],
283+
[
284+
'scope' => 'default',
285+
'destination' => '/test/src/exception_test.dart',
286+
'template' => 'dart/test/src/exception_test.dart.twig',
287+
],
283288
[
284289
'scope' => 'default',
285290
'destination' => '/test/src/response_test.dart',

templates/dart/lib/src/exception.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class {{spec.title | caseUcfirst}}Exception implements Exception {
88

99
@override
1010
String toString() {
11-
if (message == null) return "{{spec.title | caseUcfirst}}Exception";
12-
return "{{spec.title | caseUcfirst}}Exception: $type, $message (${code ?? 0})";
11+
if (message == null || message == "") return "{{spec.title | caseUcfirst}}Exception";
12+
return "{{spec.title | caseUcfirst}}Exception: ${type ?? ''}, $message (${code ?? 0})";
1313
}
1414
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:{{lang.params.packageName}}/src/exception.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
group('{{spec.title | caseUcfirst}}Exception', () {
6+
test('toString should return correct string representation', () {
7+
final exception1 = {{spec.title | caseUcfirst}}Exception();
8+
expect(exception1.toString(), equals('{{spec.title | caseUcfirst}}Exception'));
9+
10+
final exception2 = {{spec.title | caseUcfirst}}Exception('Some error message');
11+
expect(exception2.toString(), equals('{{spec.title | caseUcfirst}}Exception: , Some error message (0)'));
12+
13+
final exception3 = {{spec.title | caseUcfirst}}Exception('Invalid request', 400, 'ValidationError');
14+
expect(exception3.toString(), equals('{{spec.title | caseUcfirst}}Exception: ValidationError, Invalid request (400)'));
15+
});
16+
});
17+
}

0 commit comments

Comments
 (0)