Skip to content

Commit

Permalink
Updating some error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HelixSpiral committed Jul 25, 2023
1 parent e21c736 commit 8503310
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,4 @@ func main() {
if err != nil {
log.Fatal(err)
}

log.Println(buoyPicture)
log.Println(buoyInfo)
}
8 changes: 4 additions & 4 deletions twitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func uploadImage(image []byte) (twitterMediaResponse, error) {

fw, err := form.CreateFormFile("media", "buoyPicture.jpg")
if err != nil {
log.Fatal(err)
return twitterMediaResponse{}, fmt.Errorf("error creating file: %w", err)
}

_, err = io.Copy(fw, imageReader)
if err != nil {
log.Fatal(err)
return twitterMediaResponse{}, fmt.Errorf("error in io copy: %w", err)
}
form.Close()

Expand Down Expand Up @@ -75,12 +75,12 @@ func sendMessage(message, mediaID string) error {
resp, err := httpClient.Post("https://api.twitter.com/2/tweets", "application/json",
bytes.NewBuffer([]byte(fmt.Sprintf(`{"text": "%s", "media": {"media_ids": ["%s"]}}`, message, mediaID))))
if err != nil {
return err
return fmt.Errorf("error in http POST: %w", err)
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return err
return fmt.Errorf("error reading http body: %w", err)
}

log.Println("Tweet:", string(body))
Expand Down

0 comments on commit 8503310

Please sign in to comment.