Skip to content

Commit 8b1066e

Browse files
committed
fix: return application/problem+json when body is empty
1 parent 1a81347 commit 8b1066e

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ curl -X QUERY "http://localhost:3000/v1/validate" -H "Content-Type: application/
5757
}
5858
]
5959
}
60+
61+
### Example error response
62+
63+
All error responses are returned as [application/problem+json](https://www.rfc-editor.org/rfc/rfc9457.html)
64+
65+
```http
66+
HTTP/1.1 400 Bad Request
67+
Content-Type: application/problem+json
68+
```
69+
70+
```json
71+
{
72+
"title": "empty body",
73+
"detail": "need a body to validate",
74+
"status": 400
75+
}
6076
```
6177

6278
## Contributing

internal/handlers/validate.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/gofiber/fiber/v2"
88
publiccodeParser "github.com/italia/publiccode-parser-go/v5"
9+
"github.com/italia/publiccode-validator-api/internal/common"
910
)
1011

1112
type PubliccodeymlValidatorHandler struct {
@@ -43,9 +44,7 @@ func (vh *PubliccodeymlValidatorHandler) Query(ctx *fiber.Ctx) error {
4344
// }
4445

4546
if len(ctx.Body()) == 0 {
46-
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{
47-
"error": "empty body",
48-
})
47+
return common.Error(fiber.StatusBadRequest, "empty body", "need a body to validate")
4948
}
5049

5150
results := make(publiccodeParser.ValidationResults, 0)

0 commit comments

Comments
 (0)