Skip to content

Commit

Permalink
🐛 fix server error when missing param (#28)
Browse files Browse the repository at this point in the history
Server was responding 500 instead of 400.
  • Loading branch information
hgwood authored Jul 22, 2021
1 parent 387142a commit 1789b8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/renderPathTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import * as querystring from "querystring";
export default function renderPathTemplate(template, searchParams) {
return template.replace(/\${(.*?)}/g, (_, $1) => {
if (!searchParams.has($1)) {
throw new TypeError(
`Cannot render template: missing value for key '${$1}'`
throw Object.assign(
new Error(`Cannot render template: missing value for key '${$1}'`),
{ key: $1 }
);
}
return querystring.escape(searchParams.get($1) ?? "");
Expand Down
2 changes: 1 addition & 1 deletion src/renderPathTemplate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import renderPathTemplate from "./renderPathTemplate.js";
{
assert.throws(
() => renderPathTemplate("${var}", new URLSearchParams()),
TypeError,
{ key: "var" },
"'renderPathTemplate' does not throw on missing key"
);
}
Expand Down

0 comments on commit 1789b8b

Please sign in to comment.