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

Incorrect response codes for invalid HTTP calls #1469

Closed
2 tasks
virkt25 opened this issue Jun 25, 2018 · 6 comments · Fixed by #1658
Closed
2 tasks

Incorrect response codes for invalid HTTP calls #1469

virkt25 opened this issue Jun 25, 2018 · 6 comments · Fixed by #1658
Assignees
Labels
bug REST Issues related to @loopback/rest package and REST transport in general

Comments

@virkt25
Copy link
Contributor

virkt25 commented Jun 25, 2018

Description / Steps to reproduce / Feature proposal

From #1206

  • In examples/todo make a GET request to /todo/id using API Explorer. id shouldn't have a value (undefined).
  • You get back a 500 - Server Error BUT it should've been a 400 (Bad Request) since the request is missing the id. Same goes for an invalid id value such as -10, ten, etc.

Current Behavior

  • Invalid Response Code

Expected Behavior

Acceptance Criteria

See Reporting Issues for more tips on writing good issues

@marioestradarosa
Copy link
Contributor

marioestradarosa commented Jul 14, 2018

Also, it should be 404 , resource not found, when /model/{id} and id is a valid one but was not found in the DB. In any case I think if you try to map database operation errors with http status code will be a complicated task. For instance 404 - not found , 201 when you created a record and so on.

As a client developer I might be must interested in the response message for regular DB operations. So if I sent an operation i would do:

http.get<clientModel[]>(MyResourcreURL).suscribe( (result : clientModel) =>{} , error=>{} ); 

So I think that no matter the http satatus code, I would get to the error=> {} code right?, to show my users the appropriate message. Currently juggler is placing acceptable messages automatically for certain crud operations, the problem is that they are not being sent back to the client app thru the response object.

So, talking in the database operation arena, the errors can vary a lot, and it would be a daunting task to try match everything to http status codes.

  • Couldn't acquire the lock to update the record
  • We tried to update the record, but it no longer exists
  • Can not remove the record, it has references everywhere (key constraints)
  • That column in your SQL table, no longer exists etc.

However, currently in our lb4 app, we are sending two properties that don not conflict with status or statusCode, to send in our custom operations an appropriate error code and message, but for CRUD operations I think it is ok, once the missing message is fixed :-)

@virkt25
Copy link
Contributor Author

virkt25 commented Jul 16, 2018

Thanks for the great feedback @marioestradarosa !! You are correct in that it should be a 404 and yes we definitely need to do some work around passing errors back from the DataBase as we head towards GA -- but I also think we should try and map some (not all) of the database errors to HTTP Status Codes because some users use that to display an error message in the front end since showing DB errors can be a bit confusing.

@virkt25 virkt25 added bug LB4 GA REST Issues related to @loopback/rest package and REST transport in general labels Jul 16, 2018
@marioestradarosa
Copy link
Contributor

marioestradarosa commented Jul 16, 2018

@virkt25 this is more or less :-)

DB Basic Operations

Create

  • Successfully returns 201 + body { Record } + location header field + /{id} to locate it
  • Already Exits returns 409 + body { statusCode: 409 , message: ‘Resource with ID xx already exists, couldn't create’ }
  • General returns 500 + body { statusCode:500, message: ‘juggler original message’ }

Read

  • Successfully returns 200 + body { Record }
  • Not found returns 404 + body { statusCode: 404 , message: ‘Resource with ID xx not found’ }
  • General returns 500 + body { statusCode:500, message: ‘juggler original message’ }

Update

  • Successfully returns 200 + body { Record }
  • Not found returns 404 + body { statusCode: 404 , message: ‘Resource with ID xx not found, couldn't update' }
  • General returns 500 + body { statusCode:500, message: ‘juggler original message’ }

Delete

  • Successfully returns 200 + body { Record }
  • Not found returns 404 + body { statusCode: 404 , message: ‘Resource with ID xx not found, couldn’t delete' }
  • General returns 500 + body { statusCode:500, message: ‘juggler original message’ }

Notes 
1- { Record } is the full record, and behaves similar to the current insert operation in that it returns the defined record in the model.
2- statusCode is evaluated internally today and that’s the number placed in the http status header
3- 201 In the insert should also include A Location Header field with /newlycreatedID appended

@shimks shimks changed the title Incorrect response codes for invalid GET calls Incorrect response codes for invalid HTTP calls Jul 19, 2018
@bajtos bajtos added this to the August Milestone milestone Jul 31, 2018
@hacksparrow hacksparrow self-assigned this Aug 10, 2018
@hacksparrow
Copy link
Contributor

hacksparrow commented Aug 16, 2018

Looks like it is fixed for undefined and string id ("ten", "haha" etc.) cases in the latest master. Still 500s for invalid numerical IDs.

@virkt25
Copy link
Contributor Author

virkt25 commented Aug 16, 2018

Wonder if the fix happened because of the coercion and validation story.

@bajtos
Copy link
Member

bajtos commented Aug 23, 2018

Wonder if the fix happened because of the coercion and validation story.

Almost certainly yes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug REST Issues related to @loopback/rest package and REST transport in general
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants