From c3722430e1452ff829d6f4f8fdf02abc7e7babf4 Mon Sep 17 00:00:00 2001 From: Nemo Date: Wed, 22 Apr 2020 18:31:37 +0530 Subject: [PATCH] Adds a check for rate-limit --- spec/fixtures/ratelimit.html | 65 ++++++++++++++++++++++++++++++++++++ src/fetch.cr | 3 ++ 2 files changed, 68 insertions(+) create mode 100644 spec/fixtures/ratelimit.html diff --git a/spec/fixtures/ratelimit.html b/spec/fixtures/ratelimit.html new file mode 100644 index 0000000..31f03f3 --- /dev/null +++ b/spec/fixtures/ratelimit.html @@ -0,0 +1,65 @@ + + + + + + Too Many Free PDF Requests + + + + +
+ +
+

Too Many Free PDF Requests

+

Your IP has requested too many free PDFs too quickly.

+

Please wait before you continue downloading, and if possible slow down the rate of your requests.

+
+
+ + + \ No newline at end of file diff --git a/src/fetch.cr b/src/fetch.cr index c713b7c..eece004 100644 --- a/src/fetch.cr +++ b/src/fetch.cr @@ -71,6 +71,9 @@ module Muse::Dl if /Unable to/.match line raise Muse::Dl::Errors::MuseCorruptPDF.new("Error: MUSE is unable to generate PDF for #{url}") end + if /Your IP has requested/.match line + raise Muse::Dl::Errors::DownloadError.new("Error: MUSE Rate-limit reached") + end end end end