-
Notifications
You must be signed in to change notification settings - Fork 563
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
Document error codes for ItemResources #2384
Comments
Wouldn't documenting that both cases return a |
@Entity(name = "users")
public class User {
@Id private UUID id;
private String email;
// Getters/Setters
} @RepositoryRestResource
public interface UserRepository extends CrudRepository<User, UUID> {} $ curl -i -X "POST" "http://localhost:8080/users" \
-H 'Content-Type: application/json' \
-d $'{
"id": "0bbe06f4-9751-4f97-af16-db10eb1dcac7",
"email": "test@example.org"
}'
HTTP/1.1 201
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Location: http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7
Content-Type: application/hal+json
Transfer-Encoding: chunked
Date: Wed, 15 May 2024 14:16:05 GMT
{
"email" : "test@example.org",
"_links" : {
"self" : {
"href" : "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7"
},
"user" : {
"href" : "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7"
}
}
} Current behavior: $ curl -i -X "PUT" "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7" \
-H 'Content-Type: application/json' \
-d $'{
"id": "0bbe06f4-9751-4f97-af16-db10eb1dcac7",
"email": "changed@example.org"
}'
HTTP/1.1 200
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Location: http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7
Content-Type: application/hal+json
Transfer-Encoding: chunked
Date: Wed, 15 May 2024 14:17:43 GMT
{
"email" : "changed@example.org",
"_links" : {
"self" : {
"href" : "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7"
},
"user" : {
"href" : "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7"
}
}
}
$ curl -i -X "PUT" "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac8" \
-H 'Content-Type: application/json' \
-d $'{
"id": "0bbe06f4-9751-4f97-af16-db10eb1dcac8",
"email": "not-found@example.org"
}'
HTTP/1.1 201
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Location: http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac8
Content-Type: application/hal+json
Transfer-Encoding: chunked
Date: Wed, 15 May 2024 14:18:41 GMT
{
"email" : "not-found@example.org",
"_links" : {
"self" : {
"href" : "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac8"
},
"user" : {
"href" : "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac8"
}
}
}
$ curl -i -X "PUT" "http://localhost:8080/users/1" \
-H 'Content-Type: application/json' \
-d $'{
"id": "1",
"email": "invalid-syntax@example.org"
}'
HTTP/1.1 500
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 15 May 2024 14:19:12 GMT
Connection: close
{"cause":{"cause":null,"message":"Invalid UUID string: 1"},"message":"Failed to convert from type [java.lang.String] to type [java.util.UUID] for value [1]"}
$ curl -i -X "PUT" "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac9" \
-H 'Content-Type: application/json' \
-d $'{
"id": "0bbe06f4-9751-4f97-af16-db10eb1dcac8",
"email": "ids-do-not-match@example.org"
}'
HTTP/1.1 500
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 15 May 2024 14:36:48 GMT
Connection: close
{"timestamp":"2024-05-15T14:36:48.464+00:00","status":500,"error":"Internal Server Error","path":"/users/0bbe06f4-9751-4f97-af16-db10eb1dcac9"}
$ curl -i -X "PATCH" "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7" \
-H 'Content-Type: application/json' \
-d $'{
"email": "patched@example.org"
}'
HTTP/1.1 200
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/hal+json
Transfer-Encoding: chunked
Date: Wed, 15 May 2024 14:41:50 GMT
{
"email" : "patched@example.org",
"_links" : {
"self" : {
"href" : "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7"
},
"user" : {
"href" : "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac7"
}
}
}
$ curl -i -X "PATCH" "http://localhost:8080/users/0bbe06f4-9751-4f97-af16-db10eb1dcac8" \
-H 'Content-Type: application/json' \
-d $'{
"email": "not-found@example.org"
}'
HTTP/1.1 404
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Length: 0
Date: Wed, 15 May 2024 14:42:30 GMT
$ curl -i -X "PATCH" "http://localhost:8080/users/1" \
-H 'Content-Type: application/json' \
-d $'{
"email": "invalid-syntax@example.org"
}'
HTTP/1.1 500
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 15 May 2024 14:44:19 GMT
Connection: close
{"cause":{"cause":null,"message":"Invalid UUID string: 1"},"message":"Failed to convert from type [java.lang.String] to type [java.util.UUID] for value [1]"}
Current behavior: a) PUT id exists ⇒ Right now c and g return the same error. One might argue that f and g should return the same error. The current documentation for
Looking at Default Status Codes:
For |
https://docs.spring.io/spring-data/rest/reference/repository-resources.html#repository-resources.item-resource
Examples:
PATCH http://localhost:8080/orders/5
when no order with5
existsPATCH http://localhost:8080/orders/A
when orders have numeric IDshttps://docs.spring.io/spring-data/rest/reference/repository-resources.html#repository-resources.default-status-codes
The text was updated successfully, but these errors were encountered: