Skip to content

Commit

Permalink
Parse error message (prometheus#866)
Browse files Browse the repository at this point in the history
* Parse error message

* Update bindata.go
  • Loading branch information
w0rm authored and stuartnelson3 committed Jun 18, 2017
1 parent 525bd56 commit 6b5fb2d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
10 changes: 8 additions & 2 deletions ui/app/src/Utils/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ withDefault default response =
default


parseError : String -> Maybe String
parseError =
Json.decodeString (field "error" Json.string) >> Result.toMaybe


errorToString : Http.Error -> String
errorToString err =
case err of
Expand All @@ -27,11 +32,12 @@ errorToString err =
"Network error"

BadStatus resp ->
resp.status.message ++ " " ++ resp.body
parseError resp.body
|> Maybe.withDefault (resp.status.message ++ " " ++ resp.body)

BadPayload err resp ->
-- OK status, unexpected payload
"Unexpected response from api" ++ err
"Unexpected response from api: " ++ err

BadUrl url ->
"Malformed url: " ++ url
Expand Down
6 changes: 3 additions & 3 deletions ui/app/src/Utils/Views.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onCheck, onInput, onClick, onBlur)
import Utils.FormValidation exposing (ValidationState(..), ValidatedField)
import Utils.String


tab : tab -> tab -> (tab -> msg) -> List (Html msg) -> Html msg
Expand Down Expand Up @@ -126,6 +127,5 @@ loading =

error : String -> Html msg
error err =
div []
[ p [] [ text <| "Error: " ++ err ]
]
div [ class "alert alert-warning" ]
[ text (Utils.String.capitalizeFirst err) ]
2 changes: 1 addition & 1 deletion ui/app/src/Views/SilenceForm/Views.elm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ informationBlock silence alerts =
Views.Shared.SilencePreview.view alerts

Utils.Types.Failure error ->
div [ class "alert alert-warning" ] [ text error ]
Utils.Views.error error

Utils.Types.Loading ->
loading
Expand Down
4 changes: 2 additions & 2 deletions ui/bindata.go

Large diffs are not rendered by default.

0 comments on commit 6b5fb2d

Please sign in to comment.