From 439ec61de900c28a58e858cfde65451550ecd694 Mon Sep 17 00:00:00 2001 From: Damian Bednarczyk Date: Wed, 29 Nov 2023 15:03:44 -0600 Subject: [PATCH] rename `api.ApiError` to `api.Error` --- proxychain/responsemodifers/api/error_api.go | 5 +++-- proxychain/responsemodifers/outline_test.go | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/proxychain/responsemodifers/api/error_api.go b/proxychain/responsemodifers/api/error_api.go index 1a5e71a..333564f 100644 --- a/proxychain/responsemodifers/api/error_api.go +++ b/proxychain/responsemodifers/api/error_api.go @@ -8,7 +8,7 @@ import ( "reflect" ) -type APIError struct { +type Error struct { Success bool `json:"success"` Error ErrorDetails `json:"error"` } @@ -25,7 +25,7 @@ func CreateAPIErrReader(err error) io.ReadCloser { } baseErr := getBaseError(err) - apiErr := APIError{ + apiErr := Error{ Success: false, Error: ErrorDetails{ Message: err.Error(), @@ -50,6 +50,7 @@ func getBaseError(err error) error { if unwrapped == nil { return err } + err = unwrapped } } diff --git a/proxychain/responsemodifers/outline_test.go b/proxychain/responsemodifers/outline_test.go index aadf9f1..edc96ac 100644 --- a/proxychain/responsemodifers/outline_test.go +++ b/proxychain/responsemodifers/outline_test.go @@ -6,13 +6,15 @@ import ( "io" "net/url" "testing" + + "ladder/proxychain/responsemodifers/api" ) func TestCreateAPIErrReader(t *testing.T) { _, baseErr := url.Parse("://this is an invalid url") wrappedErr := fmt.Errorf("wrapped error: %w", baseErr) - readCloser := CreateAPIErrReader(wrappedErr) + readCloser := api.CreateAPIErrReader(wrappedErr) defer readCloser.Close() // Read and unmarshal the JSON output @@ -22,7 +24,7 @@ func TestCreateAPIErrReader(t *testing.T) { } fmt.Println(string(data)) - var apiErr APIError + var apiErr api.Error err = json.Unmarshal(data, &apiErr) if err != nil { t.Fatalf("Failed to unmarshal JSON: %v", err) @@ -41,7 +43,7 @@ func TestCreateAPIErrReader(t *testing.T) { func TestCreateAPIErrReader2(t *testing.T) { _, baseErr := url.Parse("://this is an invalid url") - readCloser := CreateAPIErrReader(baseErr) + readCloser := api.CreateAPIErrReader(baseErr) defer readCloser.Close() // Read and unmarshal the JSON output @@ -51,7 +53,7 @@ func TestCreateAPIErrReader2(t *testing.T) { } fmt.Println(string(data)) - var apiErr APIError + var apiErr api.Error err = json.Unmarshal(data, &apiErr) if err != nil { t.Fatalf("Failed to unmarshal JSON: %v", err)