Skip to content

Instantly share code, notes, and snippets.

@nichoth
Last active June 16, 2023 03:13
Show Gist options
  • Save nichoth/33cba9bfdce17b2d0800d0a6c8a430ad to your computer and use it in GitHub Desktop.
Save nichoth/33cba9bfdce17b2d0800d0a6c8a430ad to your computer and use it in GitHub Desktop.
Get an error from http request
import { HTTPError } from 'ky'
async function getErrorBody (error) {
if (error instanceof HTTPError) return (await error.response.text())
return String(error)
}
function getErrorMessage (error) {
if (error instanceof Error) return error.message
return String(error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment