rename api.ApiError to api.Error
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type APIError struct {
|
type Error struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
Error ErrorDetails `json:"error"`
|
Error ErrorDetails `json:"error"`
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ func CreateAPIErrReader(err error) io.ReadCloser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
baseErr := getBaseError(err)
|
baseErr := getBaseError(err)
|
||||||
apiErr := APIError{
|
apiErr := Error{
|
||||||
Success: false,
|
Success: false,
|
||||||
Error: ErrorDetails{
|
Error: ErrorDetails{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
@@ -50,6 +50,7 @@ func getBaseError(err error) error {
|
|||||||
if unwrapped == nil {
|
if unwrapped == nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = unwrapped
|
err = unwrapped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,15 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"ladder/proxychain/responsemodifers/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateAPIErrReader(t *testing.T) {
|
func TestCreateAPIErrReader(t *testing.T) {
|
||||||
_, baseErr := url.Parse("://this is an invalid url")
|
_, baseErr := url.Parse("://this is an invalid url")
|
||||||
wrappedErr := fmt.Errorf("wrapped error: %w", baseErr)
|
wrappedErr := fmt.Errorf("wrapped error: %w", baseErr)
|
||||||
|
|
||||||
readCloser := CreateAPIErrReader(wrappedErr)
|
readCloser := api.CreateAPIErrReader(wrappedErr)
|
||||||
defer readCloser.Close()
|
defer readCloser.Close()
|
||||||
|
|
||||||
// Read and unmarshal the JSON output
|
// Read and unmarshal the JSON output
|
||||||
@@ -22,7 +24,7 @@ func TestCreateAPIErrReader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
|
|
||||||
var apiErr APIError
|
var apiErr api.Error
|
||||||
err = json.Unmarshal(data, &apiErr)
|
err = json.Unmarshal(data, &apiErr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to unmarshal JSON: %v", err)
|
t.Fatalf("Failed to unmarshal JSON: %v", err)
|
||||||
@@ -41,7 +43,7 @@ func TestCreateAPIErrReader(t *testing.T) {
|
|||||||
func TestCreateAPIErrReader2(t *testing.T) {
|
func TestCreateAPIErrReader2(t *testing.T) {
|
||||||
_, baseErr := url.Parse("://this is an invalid url")
|
_, baseErr := url.Parse("://this is an invalid url")
|
||||||
|
|
||||||
readCloser := CreateAPIErrReader(baseErr)
|
readCloser := api.CreateAPIErrReader(baseErr)
|
||||||
defer readCloser.Close()
|
defer readCloser.Close()
|
||||||
|
|
||||||
// Read and unmarshal the JSON output
|
// Read and unmarshal the JSON output
|
||||||
@@ -51,7 +53,7 @@ func TestCreateAPIErrReader2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
|
|
||||||
var apiErr APIError
|
var apiErr api.Error
|
||||||
err = json.Unmarshal(data, &apiErr)
|
err = json.Unmarshal(data, &apiErr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to unmarshal JSON: %v", err)
|
t.Fatalf("Failed to unmarshal JSON: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user