Adds a check for rate-limit

master
Nemo 3 years ago
parent a2db89ddf7
commit c3722430e1
  1. 65
      spec/fixtures/ratelimit.html
  2. 3
      src/fetch.cr

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Too Many Free PDF Requests</title>
<style>
body {
margin: 0;
padding: 0;
}
.page429 {
display: table;
width: 100%;
padding: 60px 30px;
box-sizing: border-box;
min-height: 350px;
font-family: sans-serif;
}
.page429 .int {
display: table-cell;
vertical-align: middle;
text-align: left;
padding-left: 30px;
}
.page429 h4 {
margin-bottom: 10px;
font-weight: 700;
font-size: 24px;
}
.page429 .logo {
display: table-cell;
width: 23%;
max-width: 182px;
vertical-align: middle;
}
.page429 .logo img {
max-width: 100%;
height: auto;
}
.page429 p {
font-weight: normal;
line-height: 1.3;
}
.page429 a {
text-decoration: none;
color: #284f84;
}
</style>
</head>
<body>
<div class="page429" id="main">
<div class="logo">
<a href="https://muse.jhu.edu"><img src="/images/muselogo_notext.png" alt="MUSE logo"></a>
</div>
<div class="int">
<h4>Too Many Free PDF Requests</h4>
<p>Your IP has requested too many free PDFs too quickly.</p>
<p>Please wait before you continue downloading, and if possible slow down the rate of your requests.</p>
</div>
</div>
</body>
</html>

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

Loading…
Cancel
Save