import: github: Catch HTTP 403 error during fetch.

* guix/import/github.scm (json-fetch*): Catch 403 HTTP error that may be
  raised if a github token has not been set.

Signed-off-by: Mathieu OTHACEHE <m.othacehe@gmail.com>
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
master
Mathieu OTHACEHE 2017-01-17 09:17:30 +01:00 committed by Ludovic Courtès
parent 11f3885bb5
commit d18b79fed8
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 6 additions and 3 deletions

View File

@ -32,10 +32,13 @@
(define (json-fetch* url)
"Return a representation of the JSON resource URL (a list or hash table), or
#f if URL returns 404."
#f if URL returns 403 or 404."
(guard (c ((and (http-get-error? c)
(= 404 (http-get-error-code c)))
#f)) ;"expected" if package is unknown
(let ((error (http-get-error-code c)))
(or (= 403 error)
(= 404 error))))
#f)) ;; "expected" if there is an authentification error (403),
;; or if package is unknown (404).
;; Note: github.com returns 403 if we omit a 'User-Agent' header.
(let* ((port (http-fetch url))
(result (json->scm port)))