Skip to content

Commit

Permalink
fix(webhooks): give better error message for monitored webhooks (spin…
Browse files Browse the repository at this point in the history
…naker#2635)

Instead of bubbling semi-useless error message verbatim from JsonPath
Make it relevant and clear to the end user why monitoring for webhook failed
if the specified json path is not valid
  • Loading branch information
marchello2000 authored Jan 31, 2019
1 parent 730f6ec commit d9501fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MonitorWebhookTask implements OverridableTimeoutRetryableTask {

long backoffPeriod = TimeUnit.SECONDS.toMillis(1)
long timeout = TimeUnit.HOURS.toMillis(1)
private static final String JSON_PATH_NOT_FOUND_ERR_FMT = "Unable to parse %s: JSON property '%s' not found in response body"

@Override
long getDynamicBackoffPeriod(Stage stage, Duration taskDuration) {
Expand Down Expand Up @@ -104,7 +105,7 @@ class MonitorWebhookTask implements OverridableTimeoutRetryableTask {
try {
result = JsonPath.read(response.body, statusJsonPath)
} catch (PathNotFoundException e) {
responsePayload.webhook.monitor << [error: e.message]
responsePayload.webhook.monitor << [error: String.format(JSON_PATH_NOT_FOUND_ERR_FMT, "status", statusJsonPath)]
return new TaskResult(ExecutionStatus.TERMINAL, responsePayload)
}
if (!(result instanceof String || result instanceof Number || result instanceof Boolean)) {
Expand All @@ -117,7 +118,7 @@ class MonitorWebhookTask implements OverridableTimeoutRetryableTask {
try {
progress = JsonPath.read(response.body, progressJsonPath)
} catch (PathNotFoundException e) {
responsePayload.webhook.monitor << [error: e.message]
responsePayload.webhook.monitor << [error: String.format(JSON_PATH_NOT_FOUND_ERR_FMT, "progress", statusJsonPath)]
return new TaskResult(ExecutionStatus.TERMINAL, responsePayload)
}
if (!(progress instanceof String)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class MonitorWebhookTaskSpec extends Specification {

then:
result.status == ExecutionStatus.TERMINAL
result.context.webhook.monitor == [error: 'Missing property in path $[\'doesnt\']', body: [status: "SUCCESS"], statusCode: HttpStatus.OK, statusCodeValue: HttpStatus.OK.value()]
result.context.webhook.monitor == [error: 'Unable to parse status: JSON property \'$.doesnt.exist\' not found in response body', body: [status: "SUCCESS"], statusCode: HttpStatus.OK, statusCodeValue: HttpStatus.OK.value()]
}

def "should return TERMINAL status if jsonPath isn't evaluated to single value"() {
Expand Down

0 comments on commit d9501fa

Please sign in to comment.