Skip to content

Commit 95d4fa3

Browse files
committed
Handle case of missing OAuth provider
Signed-off-by: Sundeep Gottipati <[email protected]>
1 parent b080d81 commit 95d4fa3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

cmd/docker-mcp/internal/desktop/raw_client.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"fmt"
78
"io"
89
"net"
910
"net/http"
@@ -51,6 +52,12 @@ func (c *RawClient) Get(ctx context.Context, endpoint string, v any) error {
5152
}
5253
defer response.Body.Close()
5354

55+
// Check for HTTP errors
56+
if response.StatusCode >= 400 {
57+
buf, _ := io.ReadAll(response.Body)
58+
return fmt.Errorf("HTTP %d: %s", response.StatusCode, string(buf))
59+
}
60+
5461
buf, err := io.ReadAll(response.Body)
5562
if err != nil {
5663
return err
@@ -90,6 +97,12 @@ func (c *RawClient) Post(ctx context.Context, endpoint string, v any, result any
9097
}
9198
defer response.Body.Close()
9299

100+
// Check for HTTP errors
101+
if response.StatusCode >= 400 {
102+
buf, _ := io.ReadAll(response.Body)
103+
return fmt.Errorf("HTTP %d: %s", response.StatusCode, string(buf))
104+
}
105+
93106
if result == nil {
94107
_, err := io.Copy(io.Discard, response.Body)
95108
return err
@@ -123,6 +136,12 @@ func (c *RawClient) Delete(ctx context.Context, endpoint string) error {
123136
}
124137
defer response.Body.Close()
125138

139+
// Check for HTTP errors
140+
if response.StatusCode >= 400 {
141+
buf, _ := io.ReadAll(response.Body)
142+
return fmt.Errorf("HTTP %d: %s", response.StatusCode, string(buf))
143+
}
144+
126145
_, err = io.Copy(io.Discard, response.Body)
127146
return err
128147
}

cmd/docker-mcp/oauth/auth.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package oauth
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/docker/mcp-gateway/cmd/docker-mcp/internal/desktop"
89
)
@@ -12,9 +13,18 @@ func Authorize(ctx context.Context, app string, scopes string) error {
1213

1314
authResponse, err := client.PostOAuthApp(ctx, app, scopes, false)
1415
if err != nil {
16+
// Check if error is about provider not found
17+
if strings.Contains(err.Error(), "not found") {
18+
return fmt.Errorf("OAuth provider does not exist")
19+
}
1520
return err
1621
}
1722

23+
// Check if the response contains a valid browser URL
24+
if authResponse.BrowserURL == "" {
25+
return fmt.Errorf("OAuth provider does not exist")
26+
}
27+
1828
fmt.Printf("Opening your browser for authentication. If it doesn't open automatically, please visit: %s\n", authResponse.BrowserURL)
1929

2030
return nil

0 commit comments

Comments
 (0)