-
Notifications
You must be signed in to change notification settings - Fork 97
feat: add input validation and error handling to GetBookByID #149
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
base: main
Are you sure you want to change the base?
Conversation
|
Keploy failed to create test cases for this PR. For retrying, please click here |
|
@khareyash05 i run the program and there is no errors , once check it and please merge it , this is my fir apifellowship pr |
|
Hey @vamshi1188, I had written the following sample implementation:
Also, And for an empty ID provided like Thank you for bringing to my attention that I wasn’t returning the specific ID of the book that couldn’t be found |
| statement := `SELECT book_id, title, author, price, published_date, stock_quantity FROM books WHERE book_id = ? ;` | ||
| // Input validation | ||
| if bookID == "" { | ||
| return models.Book{}, fmt.Errorf("book ID cannot be empty") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should handle custom errors if any param is empty, maybe return a model which say things are empty so that it can be handled on the handler side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows better error handling, also helps integrating a frontend(iff.) better handle more errors
Signed-off-by: vamshi <vamshigodev@gmail.com>
Signed-off-by: vamshi <vamshigodev@gmail.com>
Signed-off-by: vamshi <vamshigodev@gmail.com>
|
Thanks for the valuable suggestions, @SaketV8 and @khareyash05. Here's what's now handled: Tested all 3 scenarios via Postman, and everything works as expected now. |
|
@khareyash05 i made changes can you please review it |




This PR improves the GetBookByID method in the BookModel by adding:
✅ Input validation to ensure bookID is not empty
✅ Proper error handling for SQL errors
✅ Graceful handling of sql.ErrNoRows when no matching book is found
✅ Contextual error messages for easier debugging
These changes make the function safer, more robust, and production-ready.