Valid
HTTP response validation
Required: no
Default: true
This directive lets you decide whether the HTTP response returned by a service is valid or not. If this directive is not present, the response is considered always valid when the status code is between 200 and 399 (inclusive).
Some services might return an HTTP status code >= 400 if there is an error. These are handled by standard error handling. But some services might return an HTTP status code < 400 (mostly the HTTP 200) and indicate an error in the response body or headers. In that case, it makes no sense to output anything from the module, but instead indicate that there is an error.
Behavior
If the
valid
directive evaluates to a false value (false
,undefined
,null
, etc.), module execution stops and Make throws an error. The execution log will display either your custom error message or a fallback message.If the
valid
directive resolves to a truthy value, the module will continue execution normally.
Basic usage examples
Both of the following forms are equivalent. You can define valid
as as simple condition (valid": "{{!body.error}}
) or as an object within a condition property plus optional message and type.
{
"response": {
"valid": {
"condition": "{{!body.error}}"
// Causes error 'Response marked as invalid.' if `error` property exists in HTTP json response body.
}
}
}
Custom error message
It is also possible to define an expected error message in this way:
{
"response": {
"valid": {
"condition": "{{!body.error}}",
"message": "Service returned HTTP {{statusCode}} with error: {{body.error}}",
"type": "UnknownError" // `RuntimeError` is the default, if type is not specified
}
}
}
Fallback error messages
{
"response": {
"valid": {
"condition": "{{body.status != 'error'}}"
// `message` not specified here, so fallback to `response.error.200` is used
},
"error": {
"200": {
"message": "Service returned error: {{body.message}}"
}
}
}
}
{
"response": {
"valid": {
"condition": "{{body.status != 'error'}}"
// `message` not specified here, so `response.error.200` is tried as fallback
},
// `200: {...}` code specific error directive also not specified, so generic `response.error` is used as fallback
"error": {
"message": "Service returned invalid status '{{body.status}}'."
}
}
}
The priority of error message resolution is as follows. The first matching is used, the rest are ignored.
Directive
response.valid.message
Directive
response.error.<statusCode>.message
Directive
response.error.message
Static message:
Response marked as invalid.
Error type resolution
The priority of error type resolution is the same as for error message
above:
Directive
response.valid.type
Directive
response.error.<statusCode>.type
Directive
response.error.type
Default type:
RuntimeError
Last updated