Skip to content

Commit fd35781

Browse files
authored
fix: Correct HTTP response status for subscription (#334)
* Correct HTTP response status for subscription Signed-off-by: Deepanshu Agarwal <[email protected]> * Remove commented code Signed-off-by: Deepanshu Agarwal <[email protected]> * Addressing comments Signed-off-by: Deepanshu Agarwal <[email protected]> Signed-off-by: Deepanshu Agarwal <[email protected]>
1 parent d3f2bc0 commit fd35781

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright 2022 The Dapr Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
/**
15+
* Http Response Status to be sent back to dapr runtime as subscription response, as per
16+
* https://docs.dapr.io/reference/api/pubsub_api/#expected-http-response
17+
*/
18+
export enum SubscribedMessageHttpResponse {
19+
SUCCESS = "SUCCESS", // Message is processed successfully
20+
RETRY = "RETRY", // Message to be retried by Dapr
21+
DROP = "DROP", // Warning is logged and message is dropped
22+
}
23+
24+
export default SubscribedMessageHttpResponse;

src/implementation/Server/HTTPServer/pubsub.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { TypeDaprPubSubCallback } from '../../../types/DaprPubSubCallback.type';
1515
import IServerPubSub from '../../../interfaces/Server/IServerPubSub';
1616
import HTTPServer from './HTTPServer';
1717
import { Logger } from '../../../logger/Logger';
18+
import SubscribedMessageHttpResponse from '../../../enum/SubscribedMessageHttpResponse.enum';
1819

1920
// https://docs.dapr.io/reference/api/pubsub_api/
2021
export default class HTTPServerPubSub implements IServerPubSub {
@@ -45,13 +46,13 @@ export default class HTTPServerPubSub implements IServerPubSub {
4546
try {
4647
await cb(data);
4748
} catch (e) {
48-
this.logger.error(`subscribe failed: ${e}`);
49-
return res.send({ success: false });
49+
this.logger.error(`[route-${topic}] Message processing failed, dropping: ${e}`);
50+
return res.send({ status: SubscribedMessageHttpResponse.DROP });
5051
}
5152

5253
// Let Dapr know that the message was processed correctly
5354
this.logger.debug(`[route-${topic}] Ack'ing the message`);
54-
return res.send({ success: true });
55+
return res.send({ status: SubscribedMessageHttpResponse.SUCCESS });
5556
});
5657
}
5758
}

0 commit comments

Comments
 (0)