-
Notifications
You must be signed in to change notification settings - Fork 96
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
How to change response code and data #102
Comments
Can you try throwing an error using one of the feathers-errors? |
Sound like I have to intercept the error from feathers-mongoose for the GET request and check that error if it's the But, I'm not quite sure where should I intercept and throw the error. Please advise. Here's my code. const service = require('feathers-mongoose');
module.exports = function() {
const app = this;
const options = {
Model: mymodels,
paginate: {
default: 5,
max: 50
}
};
app.use('/mymodels', service(options));
} |
Not having a 404 here should definitely be fixed in the adapter. To further customize the errors I am thinking of adding |
I found the root cause is caused by using Mongoose findOne with id. So, when a requested id is not in the proper ObjectId format, Mongoose throws Should we fix it by first checking the format? If it's not in ObjectId format, we throw If you think it's ok to fix this way, I would like to try to send a PR to fix it. |
@daffl I created a PR on this issue. I'm new to this community. Please advise. |
I don't think this should actually throw a 404, because if it is a bad ID (which it is) then it actually is a bad request. If you want to have a 404 you can easily add your own |
The other thing is we currently support having an alternative id field as the primary query id instead of the default |
For the hook implementation for this case see #103 (comment) |
I would like my API to return
404 Not Found
when a requested data does not exist. Currently, it responds with400 Bad Request
. How can I intercept and modify the response?Example
Request:
GET localhost/mymodels/1234
Response header:
400 Bad Request
Response Data:
{"name":"BadRequest","message":"Cast to ObjectId failed for value \"1234\" at path \"_id\"","code":400,"className":"bad-request","errors":{}}
I would like to change the response to something like this:
or just
The text was updated successfully, but these errors were encountered: