Skip to content
Snippets Groups Projects
Commit b6f32b12 authored by Ophestra's avatar Ophestra
Browse files

update readme, unmarshal errors properly

parent b9bf31bf
No related branches found
Tags v1.3.8
No related merge requests found
Image Board
-----------
Taggable image board in 1209 lines of code.
Taggable image board in 1272 lines of code.
Get it:
```shell
......
......@@ -3,9 +3,11 @@ package client
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"random.chars.jp/git/image-board/api"
)
func (r *Remote) send(req *http.Request) (*http.Response, error) {
......@@ -94,7 +96,19 @@ func unmarshal(reader io.ReadCloser, v interface{}) error {
fmt.Printf("Error closing reader after unmarshalling, %s\n", err)
}
}()
if err := json.NewDecoder(reader).Decode(v); err != nil {
var data []byte
if d, err := io.ReadAll(reader); err != nil {
return err
} else {
data = d
}
if err := json.Unmarshal(data, v); err != nil {
var errPayload api.Error
if tryErr := json.Unmarshal(data, &errPayload); tryErr == nil {
return errors.New(errPayload.Error)
}
return err
}
return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment