Skip to content

Commit

Permalink
fix(error messages): cli http request errors should show a summary wi…
Browse files Browse the repository at this point in the history
…th http status and message
  • Loading branch information
xmbhasin committed Dec 30, 2024
1 parent aad1fdd commit ecebd5b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ import Unison.Var (Var)
import Unison.Var qualified as Var
import Unison.WatchKind qualified as WK
import Witch (unsafeFrom)
import qualified Unison.Util.ColorText

reportBugURL :: Pretty
reportBugURL = "https://github.com/unisonweb/unison/issues/new"
Expand Down Expand Up @@ -1771,16 +1772,16 @@ notifyUser dir = \case
<> P.newline
<> P.indentN 2 (P.pshown response)
Servant.FailureResponse request response ->
P.wrap "Oops, I received an unexpected status code from the server."
unexpectedServerResponse response
<> P.newline
<> P.newline
<> P.wrap "Here is the request."
<> P.wrap "Here is the request:"
<> P.newline
<> P.newline
<> P.indentN 2 (P.pshown request)
<> P.newline
<> P.newline
<> P.wrap "Here is the full response."
<> P.wrap "Here is the full response:"
<> P.newline
<> P.newline
<> P.indentN 2 (P.pshown response)
Expand Down Expand Up @@ -2362,6 +2363,10 @@ prettyTransportError = \case
Share.RateLimitExceeded -> "Rate limit exceeded, please try again later."
Share.Timeout -> "The code server timed-out when responding to your request. Please try again later or report an issue if the problem persists."
Share.UnexpectedResponse resp ->
unexpectedServerResponse resp

unexpectedServerResponse :: Servant.ResponseF LazyByteString.ByteString -> P.Pretty Unison.Util.ColorText.ColorText
unexpectedServerResponse resp =
(P.lines . catMaybes)
[ Just
( "The server sent a "
Expand All @@ -2372,11 +2377,11 @@ prettyTransportError = \case
in if Text.null body then Nothing else Just (P.newline <> "Response body: " <> P.text body),
responseRequestId resp <&> \responseId -> P.newline <> "Request ID: " <> P.blue (P.text responseId)
]
where
-- Dig the request id out of a response header.
responseRequestId :: Servant.Response -> Maybe Text
responseRequestId =
fmap Text.decodeUtf8 . List.lookup "X-RequestId" . Foldable.toList @Seq . Servant.responseHeaders

-- | Dig the request id out of a response header.
responseRequestId :: Servant.Response -> Maybe Text
responseRequestId =
fmap Text.decodeUtf8 . List.lookup "X-RequestId" . Foldable.toList @Seq . Servant.responseHeaders

prettyEntityType :: Share.EntityType -> Pretty
prettyEntityType = \case
Expand Down Expand Up @@ -2928,7 +2933,7 @@ listOfNames len types terms = do
]
where
formatTerms tms =
P.lines . P.nonEmpty $ P.plural tms (P.blue "Term") : List.intersperse "" (go <$> tms)
P.lines . P.nonEmpty $ P.blue (P.plural tms "Term") : List.intersperse "" (go <$> tms)
where
go (ref, hqs) =
P.column2
Expand Down

0 comments on commit ecebd5b

Please sign in to comment.