Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HhW8LD8r3EigoBaCGrQZx5 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HhW8LD8r3EigoBaCGrQZx5
46 lines
2.0 KiB
Plaintext
46 lines
2.0 KiB
Plaintext
# What the client sees when something is wrong
|
|
|
|
|
|
--- validation: three fields wrong at once ---
|
|
$ curl -i -X POST 'localhost:8080/api/books' -H 'Content-Type: application/json' -d '{"title":"","author":"Someone","isbn":"123","price":-1}'
|
|
HTTP 400
|
|
{"detail":"Invalid request content.","instance":"/api/books","status":400,"title":"Bad Request","errors":{"isbn":"must be 13 digits starting with 978 or 979","price":"must be greater than or equal to 0.00","title":"must not be blank"}}
|
|
|
|
|
|
--- duplicate ISBN on create ---
|
|
$ curl -i -X POST 'localhost:8080/api/books' -H 'Content-Type: application/json' -d '{"title":"Java Concurrency in Practice","author":"Brian Goetz","isbn":"9780321349606","price":39.99}'
|
|
HTTP 409
|
|
{"detail":"A book with that ISBN already exists","instance":"/api/books","status":409,"title":"Conflict"}
|
|
|
|
|
|
--- duplicate ISBN on update (book 2 takes book 1's ISBN) ---
|
|
$ curl -i -X PUT 'localhost:8080/api/books/2' -H 'Content-Type: application/json' -d '{"title":"Java Concurrency in Practice","author":"Brian Goetz","isbn":"9780134685991","price":39.99}'
|
|
HTTP 409
|
|
{"detail":"A book with that ISBN already exists","instance":"/api/books/2","status":409,"title":"Conflict"}
|
|
|
|
|
|
--- the message MySQL itself produced for the duplicate ---
|
|
Duplicate entry '9780134685991' for key 'book.uk_book_isbn'
|
|
|
|
--- unknown id ---
|
|
$ curl -i -X GET 'localhost:8080/api/books/99'
|
|
HTTP 404
|
|
{"detail":"Book 99 not found","instance":"/api/books/99","status":404,"title":"Not Found"}
|
|
|
|
$ curl -i -X DELETE 'localhost:8080/api/books/99'
|
|
HTTP 404
|
|
{"detail":"Book 99 not found","instance":"/api/books/99","status":404,"title":"Not Found"}
|
|
|
|
|
|
--- the id is not a number ---
|
|
$ curl -i -X GET 'localhost:8080/api/books/abc'
|
|
HTTP 400
|
|
{"detail":"Failed to convert 'id' with value: 'abc'","instance":"/api/books/abc","status":400,"title":"Bad Request"}
|
|
|
|
|
|
--- the body is not JSON ---
|
|
$ curl -i -X POST 'localhost:8080/api/books' -H 'Content-Type: application/json' -d '{not json'
|
|
HTTP 400
|
|
{"detail":"Failed to read request","instance":"/api/books","status":400,"title":"Bad Request"}
|
|
|