maintain underlying error structs to allow for type conversion (#293)

* maintain underlying error structs to allow for type conversion and
defensive error checking

* allow Error.Is for Azure responses

* update readme, add tests to ensure type conversion

* fix whitespacing

* read me

* add import to readme example
This commit is contained in:
Quest Henkart
2023-05-04 02:48:59 +08:00
committed by GitHub
parent 24aa2005cc
commit a24581dce2
4 changed files with 46 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ package openai //nolint:testpackage // testing private field
import (
"bytes"
"errors"
"fmt"
"io"
"net/http"
@@ -106,7 +107,7 @@ func TestHandleErrorResp(t *testing.T) {
}
}`,
)),
expected: "error, status code 401, message: Access denied due to Virtual Network/Firewall rules.",
expected: "error, status code: 401, message: Access denied due to Virtual Network/Firewall rules.",
},
{
name: "503 Model Overloaded",
@@ -135,6 +136,12 @@ func TestHandleErrorResp(t *testing.T) {
t.Errorf("Unexpected error: %v , expected: %s", err, tc.expected)
t.Fail()
}
e := &APIError{}
if !errors.As(err, &e) {
t.Errorf("(%s) Expected error to be of type APIError", tc.name)
t.Fail()
}
})
}
}