solidjs / solid-docs-next

SolidJS Docs.
https://docs.solidjs.com/
212 stars 244 forks source link

The `castError` behavior of `createResource` should be documented #825

Open suguruwataru opened 1 month ago

suguruwataru commented 1 month ago

Describe the bug

https://github.com/solidjs/solid-docs/blob/883f25e17843fff81d002a80e8f9a3344556fdaf/langs/en/api/api.md?plain=1#L403

The documentation linked above says

data.error tells you if the request has errored out; if so, it contains the error thrown by the fetcher.

The second part is not true. There is a castError function that's called which modifies the error thrown by the fetcher, making sure that data.error is always an Error object, and therefore data.error is not always what the fetcher throws:

https://github.com/solidjs/solid/blob/1afe035c80f0dc2815951e648e9fa4e8cc5e6054/packages/solid/src/reactive/signal.ts#L1687-L1690

If what the fetcher throws is a string, it becomes data.error.message. If it's neither a string nor an Error, it becomes data.error.cause.

I haven't found documentation for this and had to look at the code, but I think this is definitely something that should appear in the documentation.

Your Example Website or App

N/A

Steps to Reproduce the Bug or Issue

N/A

Expected behavior

The documentation of createResource (and maybe other places where the castError is used) should mention the behavior.

Screenshots or Videos

No response

Platform

All

Additional context

No response