From 37d19403e78e8dfab24a471bee7c8ee17346e43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 8 Nov 2012 00:13:25 +0100 Subject: guix-download: Error out when the HTTP response code is not 200. * guix-download.in (http-fetch): Leave with an error message when RESPONSE's code is not 200. * tests/guix-download.sh: New file. * Makefile.am (TESTS): Add it. --- guix-download.in | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'guix-download.in') diff --git a/guix-download.in b/guix-download.in index 8d4a8bb055..44118c9e3f 100644 --- a/guix-download.in +++ b/guix-download.in @@ -32,6 +32,7 @@ exec ${GUILE-@GUILE@} -L "@guilemoduledir@" -l "$0" \ (define-module (guix-download) #:use-module (web uri) #:use-module (web client) + #:use-module (web response) #:use-module (guix ui) #:use-module (guix store) #:use-module (guix utils) @@ -58,8 +59,13 @@ exec ${GUILE-@GUILE@} -L "@guilemoduledir@" -l "$0" \ (define (http-fetch url port) "Fetch from URL over HTTP and write the result to PORT." - (let-values (((response data) (http-get url #:decode-body? #f))) - (put-bytevector port data))) + (let*-values (((response data) (http-get url #:decode-body? #f)) + ((code) (response-code response))) + (if (= code 200) + (put-bytevector port data) + (leave (_ "failed to download from `~a': ~a: ~a~%") + (uri->string url) + code (response-reason-phrase response))))) (define (ftp-fetch url port) "Fetch from URL over FTP and write the result to PORT." -- cgit v1.2.3