Skip to content

Commit b7b4912

Browse files
authored
lib: remove unnecessary else statements (cloudevents#146)
This commit removes two unnecessary else clauses in unmarshaller.js, and also extracts the throwing of TypeError of invalid content types into a separate function to avoid some code duplication. Signed-off-by: Daniel Bevenius <[email protected]>
1 parent fd99cb1 commit b7b4912

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/bindings/http/unmarshaller.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ function resolveBindingName(payload, headers) {
2222
// Structured
2323
if (allowedStructuredContentTypes.includes(contentType)) {
2424
return STRUCTURED;
25-
} else {
26-
const err = new TypeError("structured+type not allowed");
27-
err.errors = [contentType];
28-
throw err;
2925
}
26+
throwTypeError("structured+type not allowed", contentType);
3027
} else {
3128
// Binary
3229
if (allowedBinaryContentTypes.includes(contentType)) {
3330
return BINARY;
34-
} else {
35-
const err = new TypeError("content type not allowed");
36-
err.errors = [contentType];
37-
throw err;
3831
}
32+
throwTypeError("content type not allowed", contentType);
3933
}
4034
}
4135

36+
function throwTypeError(msg, contentType) {
37+
const err = new TypeError(msg);
38+
err.errors = [contentType];
39+
throw err;
40+
}
41+
4242
class Unmarshaller {
4343
constructor(receiverByBinding) {
4444
this.receiverByBinding = receiverByBinding;

0 commit comments

Comments
 (0)