File tree Expand file tree Collapse file tree 2 files changed +35
-10
lines changed
Expand file tree Collapse file tree 2 files changed +35
-10
lines changed Original file line number Diff line number Diff line change @@ -59,15 +59,21 @@ class PubSub {
5959 ///
6060 /// The PubSub system can remove the relevant messages from the subscription.
6161 Future <void > acknowledge (String subscription, String ackId) async {
62- final Client httpClient = await clientViaApplicationDefaultCredentials (
63- scopes: < String > [pubsub.PubsubApi .pubsubScope],
64- );
65- final pubsubApi = pubsub.PubsubApi (httpClient);
66- final ackIds = < String > [ackId];
67- final acknowledgeRequest = pubsub.AcknowledgeRequest (ackIds: ackIds);
68- await pubsubApi.projects.subscriptions.acknowledge (
69- acknowledgeRequest,
70- '${Config .pubsubSubscriptionsPrefix }/$subscription ' ,
71- );
62+ try {
63+ final Client httpClient = await clientViaApplicationDefaultCredentials (
64+ scopes: < String > [pubsub.PubsubApi .pubsubScope],
65+ );
66+ final pubsubApi = pubsub.PubsubApi (httpClient);
67+ final ackIds = < String > [ackId];
68+ final acknowledgeRequest = pubsub.AcknowledgeRequest (ackIds: ackIds);
69+ await pubsubApi.projects.subscriptions.acknowledge (
70+ acknowledgeRequest,
71+ '${Config .pubsubSubscriptionsPrefix }/$subscription ' ,
72+ );
73+ } catch (e) {
74+ log.error (
75+ 'Failed to acknowledge message $ackId for subscription $subscription : $e ' ,
76+ );
77+ }
7278 }
7379}
Original file line number Diff line number Diff line change 1+ // Copyright 2026 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:auto_submit/request_handling/pubsub.dart' ;
6+ import 'package:test/test.dart' ;
7+
8+ void main () {
9+ group ('PubSub' , () {
10+ test ('acknowledge handles exceptions gracefully' , () async {
11+ const pubsub = PubSub ();
12+ // This should not throw even if credentials are missing or API fails.
13+ await expectLater (
14+ pubsub.acknowledge ('test-sub' , 'test-ack-id' ),
15+ completes,
16+ );
17+ });
18+ });
19+ }
You can’t perform that action at this time.
0 commit comments