Last active
June 16, 2023 03:13
-
-
Save nichoth/33cba9bfdce17b2d0800d0a6c8a430ad to your computer and use it in GitHub Desktop.
Get an error from http request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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