Skip to content

Commit

Permalink
fix: errorToResponse was broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Vehmloewff committed Aug 3, 2022
1 parent 3e82b42 commit e0d5767
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/http.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { isBadParamsError, isForbiddenError, isNotAuthenticatedError, isNotFoundError } from './errors.ts'

// deno-lint-ignore no-explicit-any
export function errorToResponse(error: any) {
if (error.code === 'authentication') return new Response(error.message, { status: 401 })
if (error.code === 'authorization') return new Response(error.message, { status: 403 })
if (error.code === 'bad-params') return new Response(error.message, { status: 400 })
if (error.code === 'not-found') return new Response(error.message, { status: 404 })
if (isForbiddenError(error)) return new Response(error.message, { status: 403 })
if (isNotAuthenticatedError(error)) return new Response(error.message, { status: 401 })
if (isBadParamsError(error)) return new Response(error.message, { status: 400 })
if (isNotFoundError(error)) return new Response(error.message, { status: 404 })

console.error(error)

Expand Down

0 comments on commit e0d5767

Please sign in to comment.