0.2.50
This commit is contained in:
@@ -126,6 +126,7 @@ type MediaStream struct {
|
||||
type APIError struct {
|
||||
StatusCode int
|
||||
Body string
|
||||
RetryAfter string
|
||||
}
|
||||
|
||||
func (e *APIError) Error() string {
|
||||
@@ -476,7 +477,7 @@ func (c *Client) ImageResponse(ctx context.Context, cred Credentials, itemID, im
|
||||
if resp.StatusCode >= 400 {
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 2048))
|
||||
resp.Body.Close()
|
||||
return nil, &APIError{StatusCode: resp.StatusCode, Body: string(body)}
|
||||
return nil, &APIError{StatusCode: resp.StatusCode, Body: string(body), RetryAfter: resp.Header.Get("Retry-After")}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -509,7 +510,7 @@ func (c *Client) TrickplayBytes(
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 400 {
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 2048))
|
||||
return nil, &APIError{StatusCode: resp.StatusCode, Body: string(body)}
|
||||
return nil, &APIError{StatusCode: resp.StatusCode, Body: string(body), RetryAfter: resp.Header.Get("Retry-After")}
|
||||
}
|
||||
// Cap the read at what was asked for. A 200 means the range was ignored and the whole
|
||||
// file is on its way, which must not become a multi-megabyte read on a seek.
|
||||
@@ -548,7 +549,7 @@ func (c *Client) SubtitleBytes(
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 400 {
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 2048))
|
||||
return nil, &APIError{StatusCode: resp.StatusCode, Body: string(body)}
|
||||
return nil, &APIError{StatusCode: resp.StatusCode, Body: string(body), RetryAfter: resp.Header.Get("Retry-After")}
|
||||
}
|
||||
return io.ReadAll(io.LimitReader(resp.Body, MaxSubtitleBytes))
|
||||
}
|
||||
@@ -689,7 +690,7 @@ func (c *Client) do(req *http.Request, out any) error {
|
||||
// Emby error bodies can echo request details; cap what we keep and never log it
|
||||
// alongside a token.
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 2048))
|
||||
return &APIError{StatusCode: resp.StatusCode, Body: string(body)}
|
||||
return &APIError{StatusCode: resp.StatusCode, Body: string(body), RetryAfter: resp.Header.Get("Retry-After")}
|
||||
}
|
||||
if out == nil {
|
||||
_, _ = io.Copy(io.Discard, resp.Body)
|
||||
|
||||
Reference in New Issue
Block a user