Skip to content

Commit 61ffe9b

Browse files
Copilotserhalp
andauthored
fix: handle non-success HTTP status codes in URL inspection like any other (#70)
* Initial plan for issue * Initial assessment and plan for handling non-success status codes Co-authored-by: serhalp <[email protected]> * Fix $fetch to handle non-success status codes and add test coverage Co-authored-by: serhalp <[email protected]> * Remove package-lock.json as this repo uses pnpm * Fix test to check for normalizedUrl after merge and fix linting issues * Add explanatory comment for $fetch.raw usage and remove test file Co-authored-by: serhalp <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: serhalp <[email protected]> Co-authored-by: Philippe Serhal <[email protected]>
1 parent 77a2e98 commit 61ffe9b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

server/api/inspect-url.post.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ export default defineEventHandler(async (event) => {
3131
}
3232

3333
const startTime = Date.now()
34-
// TODO(serhalp) `$fetch` automatically throws on 4xx, but we'd like to treat those as valid.
34+
// Use $fetch.raw to get both response status and headers, and ignoreResponseError
35+
// to prevent automatic error throwing on 4xx/5xx responses (we want to inspect those too)
3536
const { status, headers } = await $fetch.raw(normalizedUrl, {
3637
headers: {
3738
'x-nf-debug-logging': '1',
3839
},
40+
ignoreResponseError: true,
3941
})
4042
const durationInMs = Date.now() - startTime
4143

0 commit comments

Comments
 (0)