Background (please complete the following information):
Describe the bug
When the create-server API call (and possibly others) receive invalid post data they return an error message that could better describe the issue. Invalid JSON results in an error saying that every field is missing. I know this happens in 0.7, and suspect it also happens in 1.0 Beta, although I haven't tested it.
To Reproduce
Steps to reproduce the behavior:
Request:
curl --location --request POST 'https://panel.domain.com/api/application/servers' \
--header 'Content-Type: application/json' \
--header 'Accept: Application/vnd.pterodactyl.v1+json' \
--header 'Authorization: Bearer xxx' \
--header 'Content-Type: application/json' \
--data-raw '{"invalid": "json",}'
Response:
{
"errors": [
{
"code": "required",
"detail": "The name field is required.",
"source": {
"field": "name"
}
},
{
"code": "required",
"detail": "The user field is required.",
"source": {
"field": "user"
}
},
{
"code": "required",
"detail": "The egg field is required.",
"source": {
"field": "egg"
}
},
{
"code": "required",
"detail": "The docker image field is required.",
"source": {
"field": "docker_image"
}
},
{
"code": "required",
"detail": "The startup field is required.",
"source": {
"field": "startup"
}
},
{
"code": "present",
"detail": "The environment field must be present.",
"source": {
"field": "environment"
}
},
{
"code": "required",
"detail": "The limits field is required.",
"source": {
"field": "limits"
}
},
{
"code": "required",
"detail": "The limits.memory field is required.",
"source": {
"field": "limits.memory"
}
},
{
"code": "required",
"detail": "The limits.swap field is required.",
"source": {
"field": "limits.swap"
}
},
{
"code": "required",
"detail": "The limits.disk field is required.",
"source": {
"field": "limits.disk"
}
},
{
"code": "required",
"detail": "The limits.io field is required.",
"source": {
"field": "limits.io"
}
},
{
"code": "required",
"detail": "The limits.cpu field is required.",
"source": {
"field": "limits.cpu"
}
},
{
"code": "required",
"detail": "The feature limits field is required.",
"source": {
"field": "feature_limits"
}
},
{
"code": "present",
"detail": "The feature limits.databases field must be present.",
"source": {
"field": "feature_limits.databases"
}
},
{
"code": "required",
"detail": "The allocation.default field is required.",
"source": {
"field": "allocation.default"
}
}
]
}
Expected behavior
Error could describe that JSON parsing failed.
In all technicality the errors it gave are true. It's missing all those fields. Invalid json will not have the values it's looking for either.
Yes, but its a very misleading error.
It's even more confusing when you have a full request filled out. The API docs have invalid JSON in the example, so the below call will also return a similar error. CodeCo is aware and updating the docs already, but I totally get how it's confusing to copy an example out of the unofficial API docs and get that long list of errors as a response.
curl "https://pterodactyl.app/api/application/servers" \
-H "Authorization: Bearer meowmeowmeow" \
-H "Content-Type: application/json" \
-H "Accept: Application/vnd.pterodactyl.v1+json" \
-X POST \
-d '{
"external_id": "test_server",
"name": "Test",
"user": 1,
"description": "Test server",
"egg": 15,
"pack": 1,
"docker_image": "quay.io/pterodactyl/core:java-glibc",
"startup": "java -Xms128M -Xmx 1024M -jar server.jar",
"limits": {
"memory": 512,
"swap": 0,
"disk": 1024,
"io": 500,
"cpu": 100
},
"feature_limits": {
"databases": 1,
"allocations": 2
},
"environment": {
"DL_VERSION": "1.12.2"
},
"allocation": {
"default": 28,
"additional": [
3,
19
],
},
"deploy": {
"locations": [1],
"dedicated_ip": false,
"port_range": []
},
"start_on_completion": true,
"skip_scripts": false,
"oom_disabled": true
}'
Those are unofficial docs too. @LeCodeCo I believe that is yours to fix in that regards.
Again, regardless, it's super confusing and needs to be addressed. I wrote the software and that error would confuse the shit out of me.
I was calling out that it needed to be fixed on their docs too. I wasn't saying we didn't need better error messaging.
Those are unofficial docs too. @LeCodeCo I believe that is yours to fix in that regards.
The docs have been updated to fix that incorrect part.
{
"errors": [
{
"code": "BadRequestHttpException",
"status": "400",
"detail": "The JSON data passed in the request appears to be malformed. err_code: 4 err_message: \"Syntax error\"",
"source": {
"line": 17,
"file": "/app/Http/Middleware/Api/IsValidJson.php"
},
Most helpful comment