Skip to content

Commit

Permalink
enhance error handling in HTTP helpers; improve error messages for be…
Browse files Browse the repository at this point in the history
…tter clarity
  • Loading branch information
ahmedakef committed Jan 8, 2025
1 parent e9afd7c commit f3205b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions frontend/src/Helpers/Http.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ module Helpers.Http exposing (..)

import Http


errorToString : Http.Error -> String
errorToString error =
case error of
Http.BadUrl url ->
"The URL " ++ url ++ " was invalid"

Http.Timeout ->
"Unable to reach the server, try again"

Http.NetworkError ->
"Unable to reach the server, check your network connection"

Http.BadStatus 500 ->
"The server had a problem, try again later"

Http.BadStatus 400 ->
"Verify your information and try again"
Http.BadStatus _ ->
"Unknown error"

Http.BadStatus num ->
"Unknown error" ++ String.fromInt num

Http.BadBody errorMessage ->
errorMessage
4 changes: 2 additions & 2 deletions frontend/src/Steps/Steps.elm
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ update msg state =
( Success { successState | steps = steps }, Cmd.none )

Err err ->
( Failure (err |> HttpHelper.errorToString), Cmd.none )
( Failure ("error while getting program execution steps" ++ HttpHelper.errorToString err), Cmd.none )

GotSourceCode sourceCodeResult ->
case sourceCodeResult of
Ok sourceCode ->
( Success { successState | sourceCode = sourceCode }, Cmd.none )

Err err ->
( Failure (err |> HttpHelper.errorToString), Cmd.none )
( Failure ("error while reading program source code" ++ HttpHelper.errorToString err), Cmd.none )

Next ->
if successState.position + 1 > List.length successState.steps then
Expand Down

0 comments on commit f3205b0

Please sign in to comment.