remult / remult

Full-stack CRUD, simplified, with SSOT TypeScript entities
https://remult.dev
MIT License
2.89k stars 126 forks source link

Better error message when Entity is not registered #211

Closed maral closed 1 year ago

maral commented 1 year ago

I work on a project with a friend and he does not know Remult that well. I forgot to register an entity, and when he tried to use it, it showed this error about 50 times (because with each failed request it made another):

- error TypeError: Cannot read properties of undefined (reading 'headers')
    at eval (webpack-internal:///(sc_server)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:61)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I suppose remult could detect unknown route and put some comprehensible error message, such as "route /api/something" does not exist, did you forget to register entity "Something"?

noam-honig commented 1 year ago

Hi @marai,

  1. I've fixed the router to return a 404, to clarify that it didn't find anything on that route.
  2. When I tried to consume a class with no Entity decorator from the front end - I get an exception saying:"Error: my is not a known entity, did you forget to set @Entity() or did you forget to add the '@' before the call to Entity?" in the frontend code.

What call did you make, that didn't give you that error?

Here's the repo I've used to reproduce the issue.

In any case, I've added 404 for the next release.

maral commented 1 year ago

So I crossed this issue again and again I forgot the bug is there and lost another hour of my life debugging the strange error. It triggers the same error, regardless what I do. You can reproduce the error anywhere in my repo: https://github.com/maral/catchment-areas

noam-honig commented 1 year ago

Hi @maral , we've released version 0.22.0 that'll now return a 404 not found error, that should be much clearer.

Check it out at: https://github.com/remult/remult/releases/tag/v0.22.0

maral commented 1 year ago

Confirming, it returns 404 in API calls from client. From server component (api.withRemult) it works even without registering the entity. Not sure if that is by design, but I don't mind.