Skip to content

Commit e1b04bd

Browse files
committed
Change to use promise
Signed-off-by: Fabio José <[email protected]>
1 parent 3355317 commit e1b04bd

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

examples/express-ex/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ app.post('/', function (req, res) {
2222
console.log(req.headers);
2323
console.log(req.body);
2424

25-
try {
26-
var event = unmarshaller.unmarshall(req.body, req.headers);
27-
28-
// pretty print
29-
console.log("Accepted event:");
30-
console.log(JSON.stringify(event.format(), null, 2));
31-
32-
res.status(201)
33-
.send("Event Accepted");
34-
}catch(e) {
35-
console.error(e);
36-
25+
unmarshaller.unmarshall(req.body, req.headers)
26+
.then(event => {
27+
// pretty print
28+
console.log("Accepted event:");
29+
console.log(JSON.stringify(event.format(), null, 2));
30+
31+
res.status(201)
32+
.send("Event Accepted");
33+
})
34+
.catch(err => {
35+
console.error(err);
3736
res.status(400)
3837
.header("Content-Type", "application/json")
39-
.send(JSON.stringify(e));
40-
}
38+
.send(JSON.stringify(err));
39+
});
40+
4141
});
4242

4343
app.listen(3000, function () {

examples/express-ex/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"license": "Apache-2.0",
1616
"dependencies": {
1717
"express": "^4.17.1",
18-
"cloudevents-sdk": "cloudevents/sdk-javascript#receive"
18+
"cloudevents-sdk": "cloudevents/sdk-javascript#develop"
1919
}
2020
}

0 commit comments

Comments
 (0)