From 44a4c3c8c50667a23cd276530f570ec5aa6a1d27 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 14 Jun 2023 09:29:20 -0700 Subject: [PATCH] feat(code_push_client): add `CodePushUpgradeRequiredException` (#655) --- .../lib/src/code_push_client.dart | 12 ++++++++++++ .../test/src/code_push_client_test.dart | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/shorebird_code_push_client/lib/src/code_push_client.dart b/packages/shorebird_code_push_client/lib/src/code_push_client.dart index b10359358..406090e29 100644 --- a/packages/shorebird_code_push_client/lib/src/code_push_client.dart +++ b/packages/shorebird_code_push_client/lib/src/code_push_client.dart @@ -38,6 +38,17 @@ class CodePushNotFoundException extends CodePushException { CodePushNotFoundException({required super.message, super.details}); } +/// {@template code_push_upgrade_required_exception} +/// Exception thrown when a 426 response is received. +/// {@endtemplate} +class CodePushUpgradeRequiredException extends CodePushException { + /// {@macro code_push_upgrade_required_exception} + const CodePushUpgradeRequiredException({ + required super.message, + super.details, + }); +} + /// A wrapper around [http.Client] that ensures all outbound requests /// are consistent. /// For example, all requests include the standard `x-version` header. @@ -466,6 +477,7 @@ class CodePushClient { final exceptionBuilder = switch (statusCode) { HttpStatus.conflict => CodePushConflictException.new, HttpStatus.notFound => CodePushNotFoundException.new, + HttpStatus.upgradeRequired => CodePushUpgradeRequiredException.new, _ => CodePushException.new, }; diff --git a/packages/shorebird_code_push_client/test/src/code_push_client_test.dart b/packages/shorebird_code_push_client/test/src/code_push_client_test.dart index 5f13c7be3..cbe1a3953 100644 --- a/packages/shorebird_code_push_client/test/src/code_push_client_test.dart +++ b/packages/shorebird_code_push_client/test/src/code_push_client_test.dart @@ -60,6 +60,20 @@ void main() { }); }); + test('throws CodePushUpgradeRequiredException on 426 response', () async { + when(() => httpClient.send(any())).thenAnswer( + (_) async => http.StreamedResponse( + Stream.empty(), + HttpStatus.upgradeRequired, + ), + ); + + expect( + codePushClient.getApps(), + throwsA(isA()), + ); + }); + group('createCollaborator', () { const appId = 'test-app-id'; const email = 'jane.doe@shorebird.dev';