martian
martian copied to clipboard
verify: enhance errors JSON API
The package verify
needs to be reworked to be more useful for end users.
The current JSON API looks like:
{
"errors": [
{ "message": "request(url): message: got %v, want %v" }
]
}
Having the HTTP message type and verification type mixed in with the verification failure makes it hard to distinguish what type of failure happened and forces the consumer to blindly accept the message string as is.
The message
key should continue to exist for those who want to blindly accept the full message formatting from the verifier, but should be able to use the metadata about the failure to construct their own message.
The proposed new format:
{
"errors": [
{
"header.Verifier": {
"scope": "request",
"url": "http://example.com/path",
"message": "[ existing message format ]",
"actual": "Content-Type: text/plain",
"expected": "Content-Type: image/png"
}
}
]
}
This format closely resembles the existing modifier JSON API with standard keys for the verification error.