Skip to content

Commit 2bc70e0

Browse files
[azopenai] Expand the error checking to also check when the underlying OYD resource is throttling us. (Azure#23510)
1 parent ab47572 commit 2bc70e0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sdk/ai/azopenai/client_shared_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,20 @@ func customRequireNoError(t *testing.T, err error, throttlingAllowed bool) {
438438
}
439439

440440
if throttlingAllowed {
441-
if respErr := (*azcore.ResponseError)(nil); errors.As(err, &respErr) && respErr.StatusCode == http.StatusTooManyRequests {
441+
var respErr *azcore.ResponseError
442+
443+
switch {
444+
case errors.As(err, &respErr) && respErr.StatusCode == http.StatusTooManyRequests:
442445
t.Skip("Skipping test because of throttling (http.StatusTooManyRequests)")
443446
return
444-
}
445-
446-
if errors.Is(err, context.DeadlineExceeded) {
447+
// If you're using OYD, then the response error (from Azure OpenAI) will be a 400, but the underlying text will mention
448+
// that it's 429'd.
449+
// "code": 400,
450+
// "message": "Server responded with status 429. Error message: {'error': {'code': '429', 'message': 'Rate limit is exceeded. Try again in 1 seconds.'}}"
451+
case errors.As(err, &respErr) && respErr.StatusCode == http.StatusBadRequest && strings.Contains(err.Error(), "Rate limit is exceeded"):
452+
t.Skip("Skipping test because of throttling in OYD resource")
453+
return
454+
case errors.Is(err, context.DeadlineExceeded):
447455
t.Skip("Skipping test because of throttling (DeadlineExceeded)")
448456
return
449457
}

0 commit comments

Comments
 (0)