Skip to content

Commit

Permalink
github api rate limited exceeded error is now reported and not silent…
Browse files Browse the repository at this point in the history
…ly failing

- plus suggests where to put github auth token
  • Loading branch information
stas00 committed Oct 9, 2018
1 parent 06ac6fd commit 2b730a4
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions gh-md-toc
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ gh_toc_md2html() {
if [ -f "$TOKEN" ]; then
URL="$URL?access_token=$(cat $TOKEN)"
fi
curl -s --user-agent "$gh_user_agent" \
OUTPUT="$(curl -s --user-agent "$gh_user_agent" \
--data-binary @"$gh_file_md" -H "Content-Type:text/plain" \
$URL
$URL)"

if [ "$?" != "0" ]; then
echo "XXNetworkErrorXX"
fi
if [ "$(echo "${OUTPUT}" | awk '/API rate limit exceeded/')" != "" ]; then
echo "XXRateLimitXX"
else
echo "${OUTPUT}"
fi
}


#
# Is passed string url
#
Expand Down Expand Up @@ -121,6 +128,13 @@ gh_toc(){
echo "Please make sure curl is installed and check your network connectivity"
exit 1
fi
if [ "$rawhtml" == "XXRateLimitXX" ]; then
echo "Parsing local markdown file requires access to github API"
echo "Error: You exceeded the hourly limit. See: https://developer.github.com/v3/#rate-limiting"
TOKEN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt"
echo "or place github auth token here: $TOKEN"
exit 1
fi
local toc=`echo "$rawhtml" | gh_toc_grab "$gh_src_copy"`
echo "$toc"
if [ "$need_replace" = "yes" ]; then
Expand Down

0 comments on commit 2b730a4

Please sign in to comment.