Skip to content

Commit d3b9711

Browse files
authored
Add InAppPurchaseException to platform interface (flutter#3852)
1 parent e11179d commit d3b9711

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

packages/in_app_purchase/in_app_purchase_platform_interface/lib/in_app_purchase_platform_interface.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
export 'src/errors/errors.dart';
56
export 'src/in_app_purchase_platform.dart';
67
export 'src/in_app_purchase_platform_addition.dart';
78
export 'src/in_app_purchase_platform_addition_provider.dart';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
export 'errors.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// Thrown to indicate that an action failed while interacting with the
6+
/// in_app_purchase plugin.
7+
class InAppPurchaseException implements Exception {
8+
/// Creates a [InAppPurchaseException] with the specified source and error
9+
/// [code] and optional [message].
10+
InAppPurchaseException({
11+
required this.source,
12+
required this.code,
13+
this.message,
14+
}) : assert(code != null);
15+
16+
/// An error code.
17+
final String code;
18+
19+
/// A human-readable error message, possibly null.
20+
final String? message;
21+
22+
/// Which source is the error on.
23+
final String source;
24+
25+
@override
26+
String toString() => 'InAppPurchaseException($code, $message, $source)';
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:in_app_purchase_platform_interface/src/errors/in_app_purchase_exception.dart';
7+
8+
void main() {
9+
test('toString: Should return a description of the exception', () {
10+
final InAppPurchaseException exception = InAppPurchaseException(
11+
code: 'error_code',
12+
message: 'dummy message',
13+
source: 'dummy_source',
14+
);
15+
16+
// Act
17+
final String actual = exception.toString();
18+
19+
// Assert
20+
expect(actual,
21+
'InAppPurchaseException(error_code, dummy message, dummy_source)');
22+
});
23+
}

0 commit comments

Comments
 (0)