Skip to content

Commit c303c34

Browse files
committed
modelerrors: use strconv.Atoi instead of fmt.Sscanf in ExtractHTTPStatusCode
The regex match is a simple integer string. strconv.Atoi is simpler, faster, and already imported. This also removes the fmt import. Assisted-By: docker-agent
1 parent 747c989 commit c303c34

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

pkg/modelerrors/modelerrors.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package modelerrors
77
import (
88
"context"
99
"errors"
10-
"fmt"
1110
"log/slog"
1211
"math/rand"
1312
"net"
@@ -180,8 +179,7 @@ func ExtractHTTPStatusCode(err error) int {
180179
// OpenAI SDK error format: `POST "/v1/...": 429 Too Many Requests {...}`
181180
matches := statusCodeRegex.FindStringSubmatch(err.Error())
182181
if len(matches) >= 2 {
183-
var code int
184-
if _, err := fmt.Sscanf(matches[1], "%d", &code); err == nil {
182+
if code, err := strconv.Atoi(matches[1]); err == nil {
185183
return code
186184
}
187185
}

0 commit comments

Comments
 (0)