2023-04-04 19:45:55 +00:00
|
|
|
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
|
|
|
|
package go_youtubekids_client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"mime"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/go-faster/errors"
|
|
|
|
"github.com/go-faster/jx"
|
|
|
|
|
|
|
|
"github.com/ogen-go/ogen/ogenerrors"
|
|
|
|
"github.com/ogen-go/ogen/validate"
|
|
|
|
)
|
|
|
|
|
2023-08-22 14:46:51 +00:00
|
|
|
func decodeBrowseResponse(resp *http.Response) (res *BrowseResponsePayload, err error) {
|
2023-04-04 19:45:55 +00:00
|
|
|
switch resp.StatusCode {
|
|
|
|
case 200:
|
|
|
|
// Code 200.
|
|
|
|
ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "parse media type")
|
|
|
|
}
|
|
|
|
switch {
|
|
|
|
case ct == "application/json":
|
|
|
|
buf, err := io.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
d := jx.DecodeBytes(buf)
|
|
|
|
|
|
|
|
var response BrowseResponsePayload
|
|
|
|
if err := func() error {
|
|
|
|
if err := response.Decode(d); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := d.Skip(); err != io.EOF {
|
|
|
|
return errors.New("unexpected trailing data")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
err = &ogenerrors.DecodeBodyError{
|
|
|
|
ContentType: ct,
|
|
|
|
Body: buf,
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
return &response, nil
|
|
|
|
default:
|
|
|
|
return res, validate.InvalidContentType(ct)
|
|
|
|
}
|
2023-08-22 14:46:51 +00:00
|
|
|
}
|
|
|
|
// Convenient error response.
|
|
|
|
defRes, err := func() (res *ErrorResponsePayloadStatusCode, err error) {
|
2023-04-04 19:45:55 +00:00
|
|
|
ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "parse media type")
|
|
|
|
}
|
|
|
|
switch {
|
|
|
|
case ct == "application/json":
|
|
|
|
buf, err := io.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
d := jx.DecodeBytes(buf)
|
|
|
|
|
|
|
|
var response ErrorResponsePayload
|
|
|
|
if err := func() error {
|
|
|
|
if err := response.Decode(d); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := d.Skip(); err != io.EOF {
|
|
|
|
return errors.New("unexpected trailing data")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
err = &ogenerrors.DecodeBodyError{
|
|
|
|
ContentType: ct,
|
|
|
|
Body: buf,
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
}
|
2023-08-22 14:46:51 +00:00
|
|
|
return &ErrorResponsePayloadStatusCode{
|
|
|
|
StatusCode: resp.StatusCode,
|
|
|
|
Response: response,
|
|
|
|
}, nil
|
2023-04-04 19:45:55 +00:00
|
|
|
default:
|
|
|
|
return res, validate.InvalidContentType(ct)
|
|
|
|
}
|
2023-08-22 14:46:51 +00:00
|
|
|
}()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "default")
|
2023-04-04 19:45:55 +00:00
|
|
|
}
|
2023-08-22 14:46:51 +00:00
|
|
|
return res, errors.Wrap(defRes, "error")
|
2023-04-04 19:45:55 +00:00
|
|
|
}
|