Skip to content

Commit cff10e3

Browse files
committed
fix(error messages): cli http request errors should show a summary with http status and message
1 parent aad1fdd commit cff10e3

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

unison-cli/src/Unison/CommandLine/OutputMessages.hs

+13-8
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ import Unison.Var (Var)
150150
import Unison.Var qualified as Var
151151
import Unison.WatchKind qualified as WK
152152
import Witch (unsafeFrom)
153+
import qualified Unison.Util.ColorText
153154

154155
reportBugURL :: Pretty
155156
reportBugURL = "https://github.com/unisonweb/unison/issues/new"
@@ -1771,16 +1772,16 @@ notifyUser dir = \case
17711772
<> P.newline
17721773
<> P.indentN 2 (P.pshown response)
17731774
Servant.FailureResponse request response ->
1774-
P.wrap "Oops, I received an unexpected status code from the server."
1775+
unexpectedServerResponse response
17751776
<> P.newline
17761777
<> P.newline
1777-
<> P.wrap "Here is the request."
1778+
<> P.wrap "Here is the request:"
17781779
<> P.newline
17791780
<> P.newline
17801781
<> P.indentN 2 (P.pshown request)
17811782
<> P.newline
17821783
<> P.newline
1783-
<> P.wrap "Here is the full response."
1784+
<> P.wrap "Here is the full response:"
17841785
<> P.newline
17851786
<> P.newline
17861787
<> P.indentN 2 (P.pshown response)
@@ -2362,6 +2363,10 @@ prettyTransportError = \case
23622363
Share.RateLimitExceeded -> "Rate limit exceeded, please try again later."
23632364
Share.Timeout -> "The code server timed-out when responding to your request. Please try again later or report an issue if the problem persists."
23642365
Share.UnexpectedResponse resp ->
2366+
unexpectedServerResponse resp
2367+
2368+
unexpectedServerResponse :: Servant.ResponseF LazyByteString.ByteString -> P.Pretty Unison.Util.ColorText.ColorText
2369+
unexpectedServerResponse resp =
23652370
(P.lines . catMaybes)
23662371
[ Just
23672372
( "The server sent a "
@@ -2372,11 +2377,11 @@ prettyTransportError = \case
23722377
in if Text.null body then Nothing else Just (P.newline <> "Response body: " <> P.text body),
23732378
responseRequestId resp <&> \responseId -> P.newline <> "Request ID: " <> P.blue (P.text responseId)
23742379
]
2375-
where
2376-
-- Dig the request id out of a response header.
2377-
responseRequestId :: Servant.Response -> Maybe Text
2378-
responseRequestId =
2379-
fmap Text.decodeUtf8 . List.lookup "X-RequestId" . Foldable.toList @Seq . Servant.responseHeaders
2380+
2381+
-- | Dig the request id out of a response header.
2382+
responseRequestId :: Servant.Response -> Maybe Text
2383+
responseRequestId =
2384+
fmap Text.decodeUtf8 . List.lookup "X-RequestId" . Foldable.toList @Seq . Servant.responseHeaders
23802385

23812386
prettyEntityType :: Share.EntityType -> Pretty
23822387
prettyEntityType = \case

0 commit comments

Comments
 (0)