Skip to content

Commit d236a1e

Browse files
authored
fix: return application/problem+json when body is empty (#38)
1 parent 1a81347 commit d236a1e

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ curl -X QUERY "http://localhost:3000/v1/validate" -H "Content-Type: application/
5959
}
6060
```
6161

62+
### Example error response
63+
64+
All error responses are returned using the `application/problem+json` media type,
65+
in accordance with [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457.html).
66+
67+
```http
68+
HTTP/1.1 400 Bad Request
69+
Content-Type: application/problem+json
70+
```
71+
72+
```json
73+
{
74+
"title": "empty body",
75+
"detail": "need a body to validate",
76+
"status": 400
77+
}
78+
```
79+
6280
## Contributing
6381

6482
Contributing is always appreciated, see [CONTRIBUTING.md](CONTRIBUTING.md).

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)