Compare commits
13 commits
03beb6ab30
...
5857b091be
Author | SHA1 | Date | |
---|---|---|---|
5857b091be | |||
bda92522c0 | |||
aced7c0d6e | |||
49f315a434 | |||
dcb1533b32 | |||
d9a75dbfe4 | |||
4382448dfc | |||
22c4c9a3e1 | |||
7816747ffc | |||
e9bb8a19b7 | |||
5455f2bb4f | |||
d52bb3fdf4 | |||
e5eb2d72a8 |
4 changed files with 57 additions and 6 deletions
|
@ -14,7 +14,7 @@ Pre-built binaries will soon be available on the release page on both Codeberg a
|
|||
|
||||
### Build requirements
|
||||
|
||||
- **Go:** A minimum version of Go 1.22.0 is required for installing spruce.
|
||||
- **Go:** A minimum version of Go 1.22.5 is required for installing spruce.
|
||||
Please go [here](https://go.dev/dl/) to download the latest version.
|
||||
|
||||
- **Mage (Optional):** The project includes mage targets for building and installing the binary. The main
|
||||
|
|
2
go.mod
2
go.mod
|
@ -4,6 +4,6 @@
|
|||
|
||||
module codeflow.dananglin.me.uk/apollo/enbas
|
||||
|
||||
go 1.22.0
|
||||
go 1.22.5
|
||||
|
||||
require golang.org/x/net v0.26.0
|
||||
|
|
|
@ -123,10 +123,25 @@ func (g *Client) sendRequest(method string, url string, requestBody io.Reader, o
|
|||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusBadRequest {
|
||||
return fmt.Errorf(
|
||||
"did not receive an OK response from the GoToSocial server: got %d",
|
||||
response.StatusCode,
|
||||
)
|
||||
message := struct {
|
||||
Error string `json:"error"`
|
||||
}{
|
||||
Error: "",
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(response.Body).Decode(&message); err != nil {
|
||||
return ResponseError{
|
||||
StatusCode: response.StatusCode,
|
||||
Message: "",
|
||||
MessageDecodeErr: err,
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseError{
|
||||
StatusCode: response.StatusCode,
|
||||
Message: message.Error,
|
||||
MessageDecodeErr: nil,
|
||||
}
|
||||
}
|
||||
|
||||
if object == nil {
|
||||
|
|
36
internal/client/errors.go
Normal file
36
internal/client/errors.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package client
|
||||
|
||||
import "fmt"
|
||||
|
||||
type ResponseError struct {
|
||||
StatusCode int
|
||||
Message string
|
||||
MessageDecodeErr error
|
||||
}
|
||||
|
||||
func (e ResponseError) Error() string {
|
||||
if e.MessageDecodeErr != nil {
|
||||
return fmt.Sprintf(
|
||||
"received HTTP code %d from the instance but was unable to decode the error message: %v",
|
||||
e.StatusCode,
|
||||
e.MessageDecodeErr,
|
||||
)
|
||||
}
|
||||
|
||||
if e.Message == "" {
|
||||
return fmt.Sprintf(
|
||||
"received HTTP code %d from the instance but no error message was provided",
|
||||
e.StatusCode,
|
||||
)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"message received from the instance: (%d) %q",
|
||||
e.StatusCode,
|
||||
e.Message,
|
||||
)
|
||||
}
|
Loading…
Reference in a new issue