unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Mathieu OTHACEHE <m.othacehe@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH] import: github: Catch HTTP 403 error during fetch.
Date: Tue, 17 Jan 2017 09:17:30 +0100	[thread overview]
Message-ID: <20170117081730.17927-1-m.othacehe@gmail.com> (raw)

* 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>
---

Hi,

If too many github requests are made during a guix refresh (> 60/h),
github will reject all further requests with a 403 error.

The 403 error is not catch in json-fetch* guard, so guix refresh
will exit at that point. The user never gets to error message
informing that setting a GUIX_GITHUB_TOKEN may fix the problem.

Mathieu

 guix/import/github.scm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/guix/import/github.scm b/guix/import/github.scm
index df5a6b0e0..1e0bb53d9 100644
--- a/guix/import/github.scm
+++ b/guix/import/github.scm
@@ -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)))
-- 
2.11.0

             reply	other threads:[~2017-01-17  8:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-17  8:17 Mathieu OTHACEHE [this message]
2017-01-19 16:19 ` [PATCH] import: github: Catch HTTP 403 error during fetch Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170117081730.17927-1-m.othacehe@gmail.com \
    --to=m.othacehe@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).