From 8272e86b39df89ee92c018577ecc4731230b1c2a Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 12 May 2020 11:18:56 +0200 Subject: [PATCH] lib: remove unnecessary else statements 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 --- lib/bindings/http/unmarshaller.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/bindings/http/unmarshaller.js b/lib/bindings/http/unmarshaller.js index 99688c39..d52164a7 100644 --- a/lib/bindings/http/unmarshaller.js +++ b/lib/bindings/http/unmarshaller.js @@ -22,23 +22,23 @@ function resolveBindingName(payload, headers) { // Structured if (allowedStructuredContentTypes.includes(contentType)) { return STRUCTURED; - } else { - const err = new TypeError("structured+type not allowed"); - err.errors = [contentType]; - throw err; } + throwTypeError("structured+type not allowed", contentType); } else { // Binary if (allowedBinaryContentTypes.includes(contentType)) { return BINARY; - } else { - const err = new TypeError("content type not allowed"); - err.errors = [contentType]; - throw err; } + throwTypeError("content type not allowed", contentType); } } +function throwTypeError(msg, contentType) { + const err = new TypeError(msg); + err.errors = [contentType]; + throw err; +} + class Unmarshaller { constructor(receiverByBinding) { this.receiverByBinding = receiverByBinding;