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;