Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve throwing data in resources routes #10009

Open
brookslybrand opened this issue Sep 19, 2024 · 0 comments
Open

Improve throwing data in resources routes #10009

brookslybrand opened this issue Sep 19, 2024 · 0 comments

Comments

@brookslybrand
Copy link
Contributor

brookslybrand commented Sep 19, 2024

Reproduction

StackBlitz

System Info

StackBlitz

Used Package Manager

npm

Expected Behavior

From the @brophdawg11 himself:

I imagine what we'll probably do is try to return Response.json(...) with the stuff you passed to data() and if that errors and is unable to serialize then we'll log a human readable error
That way return data({ legit: 'json' }, init) works and folks can share utility functions across resource and non-resource routes with JSON as the serialization layer. If you want to return something other than JSON you will need to return your own response
We can probably also check if it's just a string and send a text/plain response too

Actual Behavior

Returns this error (note, this is only for throw data, not return data)

{
  "message": "Unexpected Server Error",
  "stack": "Error: Unexpected Server Error\n    at errorResponseToJson (/home/projects/remix-run-remix-b2ekrr/node_modules/@remix-run/server-runtime/dist/server.js:438:26)\n    at handleResourceRequest (/home/projects/remix-run-remix-b2ekrr/node_modules/@remix-run/server-runtime/dist/server.js:429:14)\n    at async requestHandler (/home/projects/remix-run-remix-b2ekrr/node_modules/@remix-run/server-runtime/dist/server.js:156:18)\n    at async nodeHandler (/home/projects/remix-run-remix-b2ekrr/node_modules/@remix-run/dev/dist/vite/plugin.js:839:27)\n    at async eval (/home/projects/remix-run-remix-b2ekrr/node_modules/@remix-run/dev/dist/vite/plugin.js:842:15)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants