question: HttpError returned as string instead of JSON
See original GitHub issueSystem:
node: v12.9.1 npm: 6.10.2 typescript: 3.7.5
index.ts
import 'reflect-metadata';
import { createExpressServer } from 'routing-controllers';
const app = createExpressServer({
controllers: [__dirname + '/**/*.controller.js'], // even if reflection isn't used and the Controller is imported directly it doesn't work
});
app.listen(3000);
example/example.controller.ts
import { Controller, NotFoundError, Get } from "routing-controllers";
@Controller('/example')
export class ExampleController {
@Get()
public get(): string {
throw new NotFoundError('what!');
}
}
Causes the following error to be produced
Error at NotFoundError.HttpError [as constructor] (/Users/john.doe/Documents/code/routing-controllers/node_modules/routing-controllers/http-error/HttpError.js:30:23) at new NotFoundError (/Users/john.doe/Documents/code/routing-controllers/node_modules/routing-controllers/http-error/NotFoundError.js:23:28) at ExampleController.get (/Users/john.doe/Documents/code/routing-controllers/dist/example/example.controller.js:17:15) at ActionMetadata.callMethod (/Users/john.doe/Documents/code/routing-controllers/node_modules/routing-controllers/metadata/ActionMetadata.js:108:48) at /Users/john.doe/Documents/code/routing-controllers/node_modules/routing-controllers/RoutingControllers.js:99:140 at processTicksAndRejections (internal/process/task_queues.js:85:5)
According to the documentation I should expect
{
"name": "NotFoundError",
"message": "what!"
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Angular4 - Http error returned is a string instead of an object
I'm looking at a json formatted string in your sample, it's wrong in the sample or on the server. Objects aren't surrounded in...
Read more >SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >HTTP status and error codes for JSON | Cloud Storage
The following document provides reference information about the status codes and error messages that are used in the Cloud Storage JSON API.
Read more >How to Parse a JSON Request Body in Go - Alex Edwards
A solution which I've found works well is to create a decodeJSONBody() helper function, and have this return a custom malformedRequest error ...
Read more >Python Parse JSON response using requests library - PYnative
You can get a 204 error In case the JSON decoding fails. The response.json() raises an exception in the following scenario. The response...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dioio-io, @ahmedabdelhafez, @marines, @franckbattu this is expected behavior when NODE_ENV is not production.
To test locally, you can set the
development
property ofRoutingControllersOptions
, to ‘false’.I’ve created this sandbox to show.
Similar: #473, #460, #440,
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.