Skip to content

Commit e39f40f

Browse files
authored
Merge pull request #15 from bat-bs/reporting
Fix Error: DB Closed
2 parents 26f2371 + ecd359c commit e39f40f

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

apiproxy/proxy.go

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func (h *baseHandle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
124124
func (h *baseHandle) HandleAzure(w http.ResponseWriter, r *http.Request, backend string) {
125125
azureToken := ValidateToken(w, r)
126126
if azureToken == "" {
127+
http.Error(w, "Error Processing Request", http.StatusUnauthorized)
127128
return
128129
}
129130
r.Header.Set("Content-Type", "application/json")

apiproxy/response.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func NewResponse(in *http.Response) error {
3939
return err
4040
}
4141
go r.ProcessValues()
42-
defer r.db.Close()
4342
return nil
4443
}
4544

@@ -54,7 +53,6 @@ func (r *Response) GetApiKeyUUID() string {
5453
}
5554

5655
uid, err := CompareToken(hashes, apiKey)
57-
log.Println(uid, err)
5856
return uid
5957
}
6058
func (r *Response) ReadValues() error {
@@ -71,6 +69,7 @@ func (r *Response) ReadValues() error {
7169
}
7270

7371
func (r *Response) ProcessValues() {
72+
defer r.db.Close()
7473
c := r.content
7574
if c.Object != "chat.completion" {
7675
log.Printf("Untested API Endpoint '%s' is used, check the Request in the DB: %s", c.Object, c.ID)
@@ -92,6 +91,5 @@ func (r *Response) ProcessValues() {
9291
log.Println(err)
9392
return
9493
}
95-
log.Println("Written Request to DB")
9694

9795
}

apiproxy/validateToken.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ func ValidateToken(w http.ResponseWriter, r *http.Request) string {
3232
//fmt.Println("\"", apiKey, "\"")
3333
if apiKey == "Bearer " {
3434
http.Error(w, "401 - Token Empty", http.StatusUnauthorized)
35+
3536
return ""
3637
}
3738

3839
db := db.NewDB()
39-
defer db.Close()
4040

4141
hashes, err := db.LookupApiKeys("*")
4242
if err != nil || len(hashes) == 0 {

0 commit comments

Comments
 (0)