Skip to content

Conversation

@bajtos
Copy link
Member

@bajtos bajtos commented Mar 17, 2025

The initial version based on the prior work here:

Quoting from README:

import { assertOkResponse } from 'assert-ok-response'

const response = await fetch('https://example.com/not-found')
await assertOkResponse(response)
//
// Throws:
//
//  const err = new Error(`${errorMsg ?? `Cannot fetch ${res.url}`} (${res.status}): ${body}`)
//                ^
//
//  Error: Cannot fetch https://example.com/not-found (404): <!doctype html>
//  [...]
//  at assertOkResponse (file:///Users/bajtos/src/assert-ok-response/index.js:15:15)
//  at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
//  at async file:///Users/bajtos/src/assert-ok-response/x.js:4:1 {
//    statusCode: 404,
//    serverMessage: '<!doctype html>\n' +
//  [...]

Error properties:

  • statusCode (number) - The HTTP status code of the response.
  • serverMessage (string) - The response body returned by the server.

Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
@bajtos bajtos merged commit 9810110 into main Mar 18, 2025
4 checks passed
@bajtos bajtos deleted the initial-impl branch March 18, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants