mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 03:47:54 +02:00
Improve logged error messages for API failures
This commit is contained in:
parent
2b115844f4
commit
6540b4dbf6
@ -669,18 +669,18 @@ func ApiPost(path, contentType string, data []byte) ([]byte, error) {
|
|||||||
req.Header.Set("X-Hishtory-Version", "v0."+Version)
|
req.Header.Set("X-Hishtory-Version", "v0."+Version)
|
||||||
resp, err := httpClient().Do(req)
|
resp, err := httpClient().Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to POST %s: %w", path, err)
|
return nil, fmt.Errorf("failed to POST %s: %w", getServerHostname()+path, err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return nil, fmt.Errorf("failed to POST %s: status_code=%d", path, resp.StatusCode)
|
return nil, fmt.Errorf("failed to POST %s: status_code=%d", getServerHostname()+path, resp.StatusCode)
|
||||||
}
|
}
|
||||||
respBody, err := io.ReadAll(resp.Body)
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read response body from POST %s: %w", path, err)
|
return nil, fmt.Errorf("failed to read response body from POST %s: %w", getServerHostname()+path, err)
|
||||||
}
|
}
|
||||||
duration := time.Since(start)
|
duration := time.Since(start)
|
||||||
hctx.GetLogger().Infof("ApiPost(%#v): %s\n", path, duration.String())
|
hctx.GetLogger().Infof("ApiPost(%#v): %s\n", getServerHostname()+path, duration.String())
|
||||||
return respBody, nil
|
return respBody, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user