Skip to content

Commit 54f4ba8

Browse files
committed
Fail explicitly if no network connectivity
1 parent 27dbf14 commit 54f4ba8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

gh-md-toc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ gh_toc_md2html() {
5959
curl -s --user-agent "$gh_user_agent" \
6060
--data-binary @"$gh_file_md" -H "Content-Type:text/plain" \
6161
$URL
62+
if [ "$?" != "0" ]; then
63+
echo "XXNetworkErrorXX"
64+
fi
6265
}
6366

6467
#
@@ -100,14 +103,25 @@ gh_toc(){
100103

101104
if [ "$(gh_is_url "$gh_src")" == "yes" ]; then
102105
gh_toc_load "$gh_src" | gh_toc_grab "$gh_src_copy"
106+
if [ "${PIPESTATUS[0]}" != "0" ]; then
107+
echo "Could not load remote document."
108+
echo "Please check your url or network connectivity"
109+
exit 1
110+
fi
103111
if [ "$need_replace" = "yes" ]; then
104112
echo
105113
echo "!! '$gh_src' is not a local file"
106114
echo "!! Can't insert the TOC into it."
107115
echo
108116
fi
109117
else
110-
local toc=`gh_toc_md2html "$gh_src" | gh_toc_grab "$gh_src_copy"`
118+
local rawhtml=$(gh_toc_md2html "$gh_src")
119+
if [ "$rawhtml" == "XXNetworkErrorXX" ]; then
120+
echo "Parsing local markdown file requires access to github API"
121+
echo "Please make sure curl is installed and check your network connectivity"
122+
exit 1
123+
fi
124+
local toc=`echo "$rawhtml" | gh_toc_grab "$gh_src_copy"`
111125
echo "$toc"
112126
if [ "$need_replace" = "yes" ]; then
113127
local ts="<\!--ts-->"

0 commit comments

Comments
 (0)