-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3e516b
commit 30c7ad9
Showing
3 changed files
with
64 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
package graphql | ||
|
||
import "fmt" | ||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
// HTTPError represents an HTTP error with status code and response body. | ||
type HTTPError struct { | ||
Body string | ||
Body Response | ||
StatusCode int | ||
} | ||
|
||
// Error implements the error interface for HTTPError. | ||
func (e *HTTPError) Error() string { | ||
return fmt.Sprintf("returned error %v: '%s'", e.StatusCode, e.Body) | ||
jsonBody, err := json.Marshal(e.Body) | ||
if err != nil { | ||
return fmt.Sprintf("returned error %v: '%s'", e.StatusCode, e.Body) | ||
} | ||
|
||
return fmt.Sprintf("returned error %v: %s", e.StatusCode, jsonBody) | ||
} |