sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
MIT License
11.83k stars 341 forks source link

Add request method and URL to error messages #595

Closed sholladay closed 1 week ago

sholladay commented 2 weeks ago

Closes #592

This PR aims to make the error messages from Ky's TimeoutError and HTTPError more helpful by including the request method and URL.

Before:

TimeoutError: Request timed out
HTTPError: Request failed with status code 400 Bad Request

After:

TimeoutError: Request timed out: POST https://localhost:3000/
HTTPError: Request failed with status code 400 Bad Request: POST https://localhost:3000/
arty-name commented 2 weeks ago

I guess, too long URLs are not a real concern here

sholladay commented 1 week ago

The maximum length of a valid URL is around 2000 characters. Which is indeed long, but still short enough that I would expect most logging systems to handle it.

https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers

We could truncate the URL to protect against invalid URLs or in the interest of readability, but that definitely makes the log entry less useful. I’m inclined to report the URL as-is.