kit icon indicating copy to clipboard operation
kit copied to clipboard

Attempt to error better when wrong fetch is used on an endpoint

Open arackaf opened this issue 3 years ago • 0 comments

Describe the problem

I've now twice gotten burned by using the "wrong" fetch in my loaders. Running

fetch("/api/my-endpoint")

with the global fetch that's in scope will puke, since "/api/my-endpoint" has no way of resolving. Obviously you have to destructure the fetch that's passed to your loader. Simple enough, but it's an easy thing to miss when you're new (at SvelteKit), and it's maddening to debug.

Describe the proposed solution

Would it be possible for the global fetch to detect when an (otherwise valid) api endpoint is being requested, and error with something clear about needing to use the provided fetch to hit endpoints?

I know this woulnd't be foolproof, since shared loaders are (I assume?) using the browser's provided fetch, which would be hard for you all to wrap, but on the server you're already providing your own fetch, so could this check be added to that (presumably for non-production builds)?

Alternatives considered

n/a

Importance

nice to have

Additional Information

No response

arackaf avatar Dec 07 '22 04:12 arackaf