Skip to content

Commit a6ae771

Browse files
committed
fix: error handling
Signed-off-by: kyano <kyanokashi2@gmail.com>
1 parent a436b50 commit a6ae771

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

pkg/sidecar/proxy/connector_lmcache.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package proxy
1818

1919
import (
2020
"encoding/json"
21+
"fmt"
2122
"io"
2223
"net/http"
2324
"strings"
@@ -102,28 +103,25 @@ func (s *Server) decodeFirst(w http.ResponseWriter, r *http.Request, original []
102103
}
103104

104105
// tryDecode attempts to decode and returns whether prefill is needed
105-
func (s *Server) tryDecode(w http.ResponseWriter, r *http.Request) (needsPrefill bool, err error) {
106+
func (s *Server) tryDecode(w http.ResponseWriter, r *http.Request) (bool, error) {
106107
dw := &bufferedResponseWriter{}
107108
s.decoderProxy.ServeHTTP(dw, r)
108109

109110
// Check for non-success status codes
110111
if dw.statusCode < 200 || dw.statusCode >= 300 {
111-
s.logger.Error(nil, "decode request failed", "code", dw.statusCode)
112112
w.WriteHeader(dw.statusCode)
113113
if dw.buffer.Len() > 0 {
114114
w.Write([]byte(dw.buffer.String())) //nolint:all
115115
}
116-
return false, nil
116+
return false, fmt.Errorf("decode request failed with status code: %d", dw.statusCode)
117117
}
118118

119119
// Parse response to check finish_reason
120120
var response map[string]any
121121
if err := json.Unmarshal([]byte(dw.buffer.String()), &response); err != nil {
122-
s.logger.Error(err, "failed to unmarshal decoder response")
123-
// Forward response as-is if we can't parse it
124122
w.WriteHeader(dw.statusCode)
125123
w.Write([]byte(dw.buffer.String())) //nolint:all
126-
return false, nil
124+
return false, err
127125
}
128126

129127
// Check for cache_threshold finish reason
@@ -135,6 +133,7 @@ func (s *Server) tryDecode(w http.ResponseWriter, r *http.Request) (needsPrefill
135133
return true, nil
136134
}
137135
}
136+
138137
}
139138
}
140139

@@ -144,7 +143,6 @@ func (s *Server) tryDecode(w http.ResponseWriter, r *http.Request) (needsPrefill
144143
w.Header().Add(k, val)
145144
}
146145
}
147-
w.WriteHeader(dw.statusCode)
148146
w.Write([]byte(dw.buffer.String())) //nolint:all
149147

150148
return false, nil

0 commit comments

Comments
 (0)