Skip to content

Commit

Permalink
Add InAppPurchaseException to platform interface (flutter#3852)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanbeusekom committed May 10, 2021
1 parent e11179d commit d3b9711
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'src/errors/errors.dart';
export 'src/in_app_purchase_platform.dart';
export 'src/in_app_purchase_platform_addition.dart';
export 'src/in_app_purchase_platform_addition_provider.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'errors.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Thrown to indicate that an action failed while interacting with the
/// in_app_purchase plugin.
class InAppPurchaseException implements Exception {
/// Creates a [InAppPurchaseException] with the specified source and error
/// [code] and optional [message].
InAppPurchaseException({
required this.source,
required this.code,
this.message,
}) : assert(code != null);

/// An error code.
final String code;

/// A human-readable error message, possibly null.
final String? message;

/// Which source is the error on.
final String source;

@override
String toString() => 'InAppPurchaseException($code, $message, $source)';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:in_app_purchase_platform_interface/src/errors/in_app_purchase_exception.dart';

void main() {
test('toString: Should return a description of the exception', () {
final InAppPurchaseException exception = InAppPurchaseException(
code: 'error_code',
message: 'dummy message',
source: 'dummy_source',
);

// Act
final String actual = exception.toString();

// Assert
expect(actual,
'InAppPurchaseException(error_code, dummy message, dummy_source)');
});
}

0 comments on commit d3b9711

Please sign in to comment.