Skip to content

Commit bfd7f25

Browse files
committed
chore: es6 unmarshaller
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> chore: fix lint multiline if Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> Update lib/bindings/http/unmarshaller.js Co-authored-by: Lance Ball <lball@redhat.com> fix: fix pr suggestion errors Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> refactor: fix DCO in PR Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> fix: fix pr suggestion errors Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
1 parent f30c814 commit bfd7f25

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

Diff for: lib/bindings/http/unmarshaller.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@ const Commons = require("./commons.js");
44
const STRUCTURED = "structured";
55
const BINARY = "binary";
66

7-
const allowedBinaryContentTypes = [];
8-
allowedBinaryContentTypes.push(Constants.MIME_JSON);
9-
allowedBinaryContentTypes.push(Constants.MIME_OCTET_STREAM);
7+
const allowedBinaryContentTypes = [
8+
Constants.MIME_JSON,
9+
Constants.MIME_OCTET_STREAM
10+
];
1011

11-
const allowedStructuredContentTypes = [];
12-
allowedStructuredContentTypes.push(Constants.MIME_CE_JSON);
13-
14-
function validateArgs(payload, headers) {
15-
if (!payload) {
16-
throw new TypeError("payload is null or undefined");
17-
}
18-
19-
if (!headers) {
20-
throw new TypeError("headers is null or undefined");
21-
}
22-
}
12+
const allowedStructuredContentTypes = [
13+
Constants.MIME_CE_JSON
14+
];
2315

2416
// Is it binary or structured?
2517
function resolveBindingName(payload, headers) {
@@ -47,18 +39,28 @@ function resolveBindingName(payload, headers) {
4739
}
4840
}
4941

50-
const Unmarshaller = function(receiverByBinding) {
51-
this.receiverByBinding = receiverByBinding;
52-
};
42+
class Unmarshaller {
43+
constructor(receiverByBinding) {
44+
this.receiverByBinding = receiverByBinding;
45+
}
5346

54-
Unmarshaller.prototype.unmarshall = function(payload, headers) {
55-
return new Promise((resolve, reject) => {
56-
try {
57-
validateArgs(payload, headers);
47+
unmarshall(payload, headers) {
48+
return new Promise((resolve, reject) => {
49+
if (!payload) {
50+
return reject(new TypeError("payload is null or undefined"));
51+
}
52+
if (!headers) {
53+
return reject(new TypeError("headers is null or undefined"));
54+
}
5855

56+
<<<<<<< HEAD
57+
// Validation level 1
58+
const sanityHeaders = Commons.sanityAndClone(headers);
59+
=======
5960
const sanityHeaders = Commons.sanityAndClone(headers);
6061

6162
// Validation level 1
63+
>>>>>>> c722b03... fix: fix pr suggestion errors
6264
if (!sanityHeaders[Constants.HEADER_CONTENT_TYPE]) {
6365
throw new TypeError("content-type header not found");
6466
}
@@ -69,10 +71,8 @@ Unmarshaller.prototype.unmarshall = function(payload, headers) {
6971
.parse(payload, sanityHeaders);
7072

7173
resolve(cloudevent);
72-
} catch (e) {
73-
reject(e);
74-
}
75-
});
76-
};
74+
});
75+
}
76+
}
7777

7878
module.exports = Unmarshaller;

0 commit comments

Comments
 (0)