Skip to content

Commit

Permalink
fix: typecheck method
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Aug 22, 2023
1 parent 000a4e1 commit d9c0008
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions node/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,17 @@ const addExcludedPatterns = (
* Normalizes method names into arrays of uppercase strings.
* (e.g. "get" becomes ["GET"])
*/
const normalizeMethods = (method: undefined | string | string[]) => {
if (!method) return

const normalizeMethods = (method: unknown, name: string): string[] => {
const methods = Array.isArray(method) ? method : [method]
return methods.map((method) => method.toUpperCase())
return methods.map((method) => {
if (typeof method !== 'string') {
throw new TypeError(
`Could not parse method declaration of function '${name}'. Expecting HTTP Method, got ${method}`,
)
}

return method.toUpperCase()
})
}

const generateManifest = ({
Expand Down Expand Up @@ -155,7 +161,7 @@ const generateManifest = ({
}

if ('method' in declaration) {
route.methods = normalizeMethods(declaration.method)
route.methods = normalizeMethods(declaration.method, func.name)
}

if ('path' in declaration) {
Expand Down

0 comments on commit d9c0008

Please sign in to comment.