@@ -459,10 +459,11 @@ func invoke(ctx context.Context, client *http.Client, url, requestID string, bri
459459 endpointRes , err := client .Do (endpointReq )
460460 now := time .Now ()
461461 if err != nil {
462+ err = fmt .Errorf ("can't connect to %s: %v (check that -e,--endpoint is correct)" , LocalEndpoint , tidyErr (err ))
462463 if observer != nil {
463464 observer .ObserveResponse (now , & runRequest , err , nil , nil )
464465 }
465- return fmt . Errorf ( "failed to contact local application endpoint (%s): %v. Please check that -e,--endpoint is correct." , LocalEndpoint , err )
466+ return err
466467 }
467468
468469 // Buffer the response body in memory.
@@ -473,10 +474,11 @@ func invoke(ctx context.Context, client *http.Client, url, requestID string, bri
473474 _ , err = io .Copy (endpointResBody , endpointRes .Body )
474475 endpointRes .Body .Close ()
475476 if err != nil {
477+ err = fmt .Errorf ("read error from %s: %v" , LocalEndpoint , tidyErr (err ))
476478 if observer != nil {
477479 observer .ObserveResponse (now , & runRequest , err , endpointRes , nil )
478480 }
479- return fmt . Errorf ( "failed to read response from local application endpoint (%s): %v" , LocalEndpoint , err )
481+ return err
480482 }
481483 endpointRes .Body = io .NopCloser (endpointResBody )
482484 endpointRes .ContentLength = int64 (endpointResBody .Len ())
@@ -485,10 +487,11 @@ func invoke(ctx context.Context, client *http.Client, url, requestID string, bri
485487 if endpointRes .StatusCode == http .StatusOK && endpointRes .Header .Get ("Content-Type" ) == "application/proto" {
486488 var runResponse sdkv1.RunResponse
487489 if err := proto .Unmarshal (endpointResBody .Bytes (), & runResponse ); err != nil {
490+ err = fmt .Errorf ("invalid response from %s: %v" , LocalEndpoint , tidyErr (err ))
488491 if observer != nil {
489492 observer .ObserveResponse (now , & runRequest , err , endpointRes , nil )
490493 }
491- return fmt . Errorf ( "invalid response from local application endpoint (%s): %v" , LocalEndpoint , err )
494+ return err
492495 }
493496 switch runResponse .Status {
494497 case sdkv1 .Status_STATUS_OK :
@@ -638,3 +641,18 @@ func randomSessionID() string {
638641 i .SetBytes (b [:])
639642 return i .Text (62 ) // base62
640643}
644+
645+ var (
646+ errConnectionRefused = errors .New ("connection refused" )
647+ )
648+
649+ func tidyErr (err error ) error {
650+ var errno syscall.Errno
651+ if errors .As (err , & errno ) {
652+ switch errno {
653+ case syscall .ECONNREFUSED :
654+ return errConnectionRefused
655+ }
656+ }
657+ return err
658+ }
0 commit comments