@@ -4,22 +4,14 @@ const Commons = require("./commons.js");
4
4
const STRUCTURED = "structured" ;
5
5
const BINARY = "binary" ;
6
6
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
+ ] ;
10
11
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
+ ] ;
23
15
24
16
// Is it binary or structured?
25
17
function resolveBindingName ( payload , headers ) {
@@ -47,18 +39,28 @@ function resolveBindingName(payload, headers) {
47
39
}
48
40
}
49
41
50
- const Unmarshaller = function ( receiverByBinding ) {
51
- this . receiverByBinding = receiverByBinding ;
52
- } ;
42
+ class Unmarshaller {
43
+ constructor ( receiverByBinding ) {
44
+ this . receiverByBinding = receiverByBinding ;
45
+ }
53
46
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
+ }
58
55
56
+ < << << << HEAD
57
+ // Validation level 1
58
+ const sanityHeaders = Commons . sanityAndClone ( headers ) ;
59
+ = === ===
59
60
const sanityHeaders = Commons . sanityAndClone ( headers ) ;
60
61
61
62
// Validation level 1
63
+ > >>> >>> c722b03 . . . fix : fix pr suggestion errors
62
64
if ( ! sanityHeaders [ Constants . HEADER_CONTENT_TYPE ] ) {
63
65
throw new TypeError ( "content-type header not found" ) ;
64
66
}
@@ -69,10 +71,8 @@ Unmarshaller.prototype.unmarshall = function(payload, headers) {
69
71
. parse ( payload , sanityHeaders ) ;
70
72
71
73
resolve ( cloudevent ) ;
72
- } catch ( e ) {
73
- reject ( e ) ;
74
- }
75
- } ) ;
76
- } ;
74
+ } ) ;
75
+ }
76
+ }
77
77
78
78
module . exports = Unmarshaller ;
0 commit comments