-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Has one relation error (MODEL_NOT_FOUND) #4278
Comments
@sujeshthekkepatt thank you for reporting the issue. Please create a small app we can run to reproduce the issue, see https://loopback.io/doc/en/contrib/Reporting-issues.html#loopback-3x-bugs |
@bajtos I have added the necessary code for reproduction. The forked repo can be found here. Steps for reproduction
|
@bajtos Any updates ? |
Just for the information: it's necessary to login and set the access token in API Explorer first, before calling this endpoint. Other steps work as described and I did receive the same error as you. |
I am also able to reproduce the problem when I call |
The weird part is that we have a test in loopback to verify that 404 Not Found error is returned when the target model of HasOne relation was not found, see here: loopback/test/relations.integration.js Lines 1809 to 1815 in 2db09a3
Model definitions: Oh! I think I see the problem now. The application correctly returns HTTP status code 404, but the error message is misleading. {
"error": {
"statusCode": 404,
"name": "Error",
"message": "Unknown \"myanothermodel\" id \"undefined\".",
"code": "MODEL_NOT_FOUND"
}
} @sujeshthekkepatt could you please confirm you are seeing 404 status code too? What happens under the hood: LoopBack's REST API layer calls juggler's method to retrieve the target model of HasOne relation. This methods returns Here is the relevant code: Lines 564 to 573 in 2db09a3
Maybe we can improve the error message as follows? var fk = ctx.getArgByName('fk');
var msg = fk
? g.f('Unknown "%s" id "%s".', toModelName, fk)
: g.f('No "%s" instance(s) found', toModelName);
var error = new Error(msg); With this change in place, I am getting the following HTTP response: {
"error": {
"statusCode": 404,
"name": "Error",
"message": "No \"myanothermodel\" instance(s) found",
"code": "MODEL_NOT_FOUND"
}
} Thoughts? |
@bajtos yes I am also getting 404. Yep the current error message is not a proper one. But returning |
Any update on this @bajtos ? |
The current behavior is intentional. The 404 error object is created only when you call the endpoint via REST API. Without this interception, your HTTP clients will get |
@bajtos In that case as you suggested, improving the error message seems a perfect fit. May be I can give a PR . |
Great! See our Contributing guide and Submitting a pull request to LoopBack 4 to get started. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I have two models
usermodal,my_another_model
.usermodel
has a hasOne relationship withmy_another_model
. Whenever I access the given endpoint I get the following error. This happens only when themy_another_model
does not have any data. The issue happens when I GET the endpoint/usermodel/me/myAnotherModel
Endpoint
usermodel
my_another_model
Error Message
I get the following error message,
The text was updated successfully, but these errors were encountered: