diff --git a/README.md b/README.md index 4ef3cea..570c77c 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,24 @@ curl -X QUERY "http://localhost:3000/v1/validate" -H "Content-Type: application/ } ``` +### Example error response + +All error responses are returned using the `application/problem+json` media type, +in accordance with [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457.html). + +```http +HTTP/1.1 400 Bad Request +Content-Type: application/problem+json +``` + +```json +{ + "title": "empty body", + "detail": "need a body to validate", + "status": 400 +} +``` + ## Contributing Contributing is always appreciated, see [CONTRIBUTING.md](CONTRIBUTING.md). diff --git a/internal/handlers/validate.go b/internal/handlers/validate.go index 8d7dcf2..9b467b2 100644 --- a/internal/handlers/validate.go +++ b/internal/handlers/validate.go @@ -6,6 +6,7 @@ import ( "github.com/gofiber/fiber/v2" publiccodeParser "github.com/italia/publiccode-parser-go/v5" + "github.com/italia/publiccode-validator-api/internal/common" ) type PubliccodeymlValidatorHandler struct { @@ -43,9 +44,7 @@ func (vh *PubliccodeymlValidatorHandler) Query(ctx *fiber.Ctx) error { // } if len(ctx.Body()) == 0 { - return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{ - "error": "empty body", - }) + return common.Error(fiber.StatusBadRequest, "empty body", "need a body to validate") } results := make(publiccodeParser.ValidationResults, 0)