Compare commits

..

13 commits

Author SHA1 Message Date
5857b091be
liking and unliking statuses 2024-07-04 11:30:40 +01:00
bda92522c0
checkpoint: status actions 2024-07-04 11:30:40 +01:00
aced7c0d6e
followers and followings 2024-07-04 11:30:40 +01:00
49f315a434
private note 2024-07-04 11:30:40 +01:00
dcb1533b32
timelines, follow requests 2024-07-04 11:30:40 +01:00
d9a75dbfe4
polls 2024-07-04 11:30:39 +01:00
4382448dfc
add a ToC to manual 2024-07-04 11:30:39 +01:00
22c4c9a3e1
checkpoint: list section complete 2024-07-04 11:30:39 +01:00
7816747ffc
checkpoint: more work on user manual 2024-07-04 11:30:39 +01:00
e9bb8a19b7
checkpoint: document account actions 2024-07-04 11:30:38 +01:00
5455f2bb4f
checkpoint: begin writing the user manual 2024-07-04 11:30:38 +01:00
d52bb3fdf4
fix: print error messages from instance
If an error occurs when sending a request to an instance, try and decode
and print the error message back to the user.
2024-07-04 11:27:00 +01:00
e5eb2d72a8
fix: set minimum go version to 1.22.5 2024-07-03 23:25:22 +01:00
4 changed files with 57 additions and 6 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.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. 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.0 go 1.22.5
require golang.org/x/net v0.26.0 require golang.org/x/net v0.26.0

View file

@ -123,10 +123,25 @@ 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 {
return fmt.Errorf( message := struct {
"did not receive an OK response from the GoToSocial server: got %d", Error string `json:"error"`
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 {

36
internal/client/errors.go Normal file
View 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,
)
}