Compare commits

..

11 commits

4 changed files with 6 additions and 57 deletions

View file

@ -14,7 +14,7 @@ Pre-built binaries will soon be available on the release page on both Codeberg a
### Build requirements ### Build requirements
- **Go:** A minimum version of Go 1.22.5 is required for installing spruce. - **Go:** A minimum version of Go 1.22.0 is required for installing spruce.
Please go [here](https://go.dev/dl/) to download the latest version. 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 - **Mage (Optional):** The project includes mage targets for building and installing the binary. The main

2
go.mod
View file

@ -4,6 +4,6 @@
module codeflow.dananglin.me.uk/apollo/enbas module codeflow.dananglin.me.uk/apollo/enbas
go 1.22.5 go 1.22.0
require golang.org/x/net v0.26.0 require golang.org/x/net v0.26.0

View file

@ -123,25 +123,10 @@ func (g *Client) sendRequest(method string, url string, requestBody io.Reader, o
defer response.Body.Close() defer response.Body.Close()
if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusBadRequest { if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusBadRequest {
message := struct { return fmt.Errorf(
Error string `json:"error"` "did not receive an OK response from the GoToSocial server: got %d",
}{ response.StatusCode,
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 { if object == nil {

View file

@ -1,36 +0,0 @@
// 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,
)
}