Skip to content

Commit b677e6e

Browse files
authored
Merge pull request #50 from stas00/master
fix silent github api rate limited exceeded problem
2 parents 06ac6fd + 2b730a4 commit b677e6e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

gh-md-toc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,21 @@ gh_toc_md2html() {
5656
if [ -f "$TOKEN" ]; then
5757
URL="$URL?access_token=$(cat $TOKEN)"
5858
fi
59-
curl -s --user-agent "$gh_user_agent" \
59+
OUTPUT="$(curl -s --user-agent "$gh_user_agent" \
6060
--data-binary @"$gh_file_md" -H "Content-Type:text/plain" \
61-
$URL
61+
$URL)"
62+
6263
if [ "$?" != "0" ]; then
6364
echo "XXNetworkErrorXX"
6465
fi
66+
if [ "$(echo "${OUTPUT}" | awk '/API rate limit exceeded/')" != "" ]; then
67+
echo "XXRateLimitXX"
68+
else
69+
echo "${OUTPUT}"
70+
fi
6571
}
6672

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

0 commit comments

Comments
 (0)