diff options
-rw-r--r-- | guix-build-coordinator/agent-messaging/http.scm | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm index 1f1b5de..3f4f5ba 100644 --- a/guix-build-coordinator/agent-messaging/http.scm +++ b/guix-build-coordinator/agent-messaging/http.scm @@ -409,7 +409,8 @@ port. Also, the port used can be changed by passing the --port option.\n" (define* (coordinator-http-request coordinator-uri agent-uuid password path - #:key method body (headers '())) + #:key method body (headers '()) + succeed-on-access-denied-retry?) (define auth-value (string-append "Basic " @@ -421,6 +422,8 @@ port. Also, the port used can be changed by passing the --port option.\n" (coordinator-uri-for-path coordinator-uri path)) + (define first-request-failed? #f) + (define (make-request) (let-values (((response body) (http-request uri @@ -436,10 +439,11 @@ port. Also, the port used can be changed by passing the --port option.\n" (current-error-port) "error: coordinator-http-request: ~A ~A: ~A\n" method path (response-code response)) - (error (catch #t + (let ((body + (catch #t (lambda () - (if (eq? '(application/json (charset . "utf-8")) - (response-content-type response)) + (if (equal? '(application/json (charset . "utf-8")) + (response-content-type response)) (json-string->scm (utf8->string body)) (utf8->string body))) (lambda (key . args) @@ -448,6 +452,20 @@ port. Also, the port used can be changed by passing the --port option.\n" "error decoding body ~A ~A\n" key args) #f)))) + (if (and first-request-failed? + succeed-on-access-denied-retry? + (equal? body + '(("error" . "access denied")))) + (begin + (simple-format + (current-error-port) + "warning: treating access denied response as success\n") + (values body response)) + (begin + (set! first-request-failed? #t) + (raise-exception + (make-exception-with-message + body)))))) (values (json-string->scm (utf8->string body)) response)))) |