Skip to content

Commit

Permalink
feat(code_push_client): add CodePushUpgradeRequiredException (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Jun 14, 2023
1 parent 1450ae2 commit 44a4c3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/shorebird_code_push_client/lib/src/code_push_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -466,6 +477,7 @@ class CodePushClient {
final exceptionBuilder = switch (statusCode) {
HttpStatus.conflict => CodePushConflictException.new,
HttpStatus.notFound => CodePushNotFoundException.new,
HttpStatus.upgradeRequired => CodePushUpgradeRequiredException.new,
_ => CodePushException.new,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodePushUpgradeRequiredException>()),
);
});

group('createCollaborator', () {
const appId = 'test-app-id';
const email = 'jane.doe@shorebird.dev';
Expand Down

0 comments on commit 44a4c3c

Please sign in to comment.