Skip to content

Commit

Permalink
Merge pull request #21 from brandly/brandly/github-errors
Browse files Browse the repository at this point in the history
give better feedback on common GitHub http errors
  • Loading branch information
erkal authored Apr 18, 2020
2 parents a5c8fd6 + ab4bf25 commit 7f143fe
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/Generators/ElmDep.elm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ getPathsOfElmFiles m token =
gitHubGet
{ path = "/repos/" ++ m.repoNameInput ++ "/git/trees/master?recursive=1"
, token = token
, expect = Http.expectJson GotPathsOfElmFiles pathsOfElmFilesDecoder
, expect =
Http.expectJson
(Result.mapError reportGitHubError >> GotPathsOfElmFiles)
pathsOfElmFilesDecoder
}


Expand All @@ -154,14 +157,31 @@ gitHubGet { token, path, expect } =
}


reportGitHubError : Http.Error -> String
reportGitHubError error =
case error of
Http.BadStatus 404 ->
"Repo not found. Is it a private repo? Use an access token!"

Http.NetworkError ->
String.join " "
[ "Network Error."
, "This can happen when hitting GitHub's rate limits."
, "Using an access token increases these limits!"
]

_ ->
"Couldn't connect to github."


pathsOfElmFilesDecoder : Decoder (List String)
pathsOfElmFilesDecoder =
JD.field "tree" (JD.list (JD.field "path" JD.string))
|> JD.map (List.filter (String.endsWith ".elm"))


type Msg
= GotPathsOfElmFiles (Result Http.Error (List String))
= GotPathsOfElmFiles (Result String (List String))
| GotRawElmFile (Result Http.Error String)
| ChangeRepo String
| ChangeToken String
Expand Down Expand Up @@ -267,10 +287,8 @@ update msg m =
, Cmd.none
)

_ ->
( { m
| state = Error "Couldn't connect to github."
}
Err error ->
( { m | state = Error error }
, Cmd.none
)

Expand Down

0 comments on commit 7f143fe

Please sign in to comment.