@@ -22,7 +22,8 @@ module Summoner.License
2222 , showLicenseWithDesc
2323 ) where
2424
25- import Colourista (errorMessage )
25+ import Colourista (errorMessage , infoMessage , warningMessage )
26+ import Control.Exception (try )
2627import Data.Aeson.Micro (FromJSON (.. ), decodeStrict , withObject , (.:) )
2728import Shellmet (($|) )
2829
@@ -106,18 +107,29 @@ fetchLicense :: LicenseName -> IO License
106107fetchLicense NONE = pure $ License $ licenseShortDesc NONE
107108fetchLicense name = do
108109 let licenseLink = " https://api.github.com/licenses/" <> githubLicenseQueryNames name
109- licenseJson <- " curl" $|
110+ curlResult <- try @ SomeException $ " curl" $|
110111 [ licenseLink
111112 , " -H"
112113 , " Accept: application/vnd.github.drax-preview+json"
113114 , " --silent"
114115 , " --fail"
115116 ]
116117
117- whenNothing (decodeStrict @ License $ encodeUtf8 licenseJson) $ do
118- errorMessage $ " Error downloading license: " <> show name
119- putTextLn $ " Fetched content:\n " <> licenseJson
120- exitFailure
118+ case curlResult of
119+ Left _ -> do
120+ errorMessage $ " Error fetching license: " <> show name
121+ warningMessage " The GitHub API rate limit may have been exceeded."
122+ warningMessage " This can happen when using a VPN or a shared network."
123+ infoMessage " Possible workarounds:"
124+ infoMessage " * Wait a few minutes and try again"
125+ infoMessage " * Try from a different network (e.g. disable VPN)"
126+ infoMessage " * Choose the 'NONE' license and add the LICENSE file manually"
127+ exitFailure
128+ Right licenseJson ->
129+ whenNothing (decodeStrict @ License $ encodeUtf8 licenseJson) $ do
130+ errorMessage $ " Error downloading license: " <> show name
131+ putTextLn $ " Fetched content:\n " <> licenseJson
132+ exitFailure
121133
122134{- | Fetches the license by given name and customises user information where
123135applicable.
0 commit comments