Open
Description
When returning something different than 2xx, the Alertmanager API returns a plain text body. E.g.
$ curl -sv -H "Content-Type: application/json" http://localhost:9093/api/v2/silences -d '{"comment":"", "createdBy":"", "endsAt":"","matchers":[{"isRegex": false, "name":"foo","value":"bar"}],"startsAt":""}'
* Trying 127.0.0.1:9093...
* Connected to localhost (127.0.0.1) port 9093 (#0)
> POST /api/v2/silences HTTP/1.1
> Host: localhost:9093
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 117
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Vary: Origin
< Vary: Accept-Encoding
< Date: Thu, 04 Aug 2022 09:41:13 GMT
< Content-Length: 63
<
"Failed to create silence: start time must be before end time"
* Connection #0 to host localhost left intact
But an error returned by prom-label-proxy would format the error message as a Prometheus API response.
Note that when a validation error happens at the OpenAPI level, the format of the response is different (e.g. it's valid JSON):
curl -sv -H "Content-Type: application/json" http://localhost:9093/api/v2/silences -d '{"comment":"", "createdBy":"", "endsAt":"","matchers":[{"isRegex": false, "name":"foo","value":"bar"}]}'
* Trying 127.0.0.1:9093...
* Connected to localhost (127.0.0.1) port 9093 (#0)
> POST /api/v2/silences HTTP/1.1
> Host: localhost:9093
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 103
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 422 Unprocessable Entity
< Content-Type: application/json
< Vary: Origin
< Vary: Accept-Encoding
< Date: Thu, 04 Aug 2022 09:42:04 GMT
< Content-Length: 53
<
* Connection #0 to host localhost left intact
{"code":602,"message":"startsAt in body is required"}