mirror of
https://github.com/LukeHagar/plexgo.git
synced 2025-12-06 04:20:46 +00:00
1218 lines
35 KiB
Go
1218 lines
35 KiB
Go
// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
|
|
package plexgo
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"github.com/LukeHagar/plexgo/internal/config"
|
|
"github.com/LukeHagar/plexgo/internal/hooks"
|
|
"github.com/LukeHagar/plexgo/internal/utils"
|
|
"github.com/LukeHagar/plexgo/models/operations"
|
|
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
|
"github.com/LukeHagar/plexgo/retry"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// Butler is the task manager of the Plex Media Server Ecosystem.
|
|
type Butler struct {
|
|
rootSDK *PlexAPI
|
|
sdkConfiguration config.SDKConfiguration
|
|
hooks *hooks.Hooks
|
|
}
|
|
|
|
func newButler(rootSDK *PlexAPI, sdkConfig config.SDKConfiguration, hooks *hooks.Hooks) *Butler {
|
|
return &Butler{
|
|
rootSDK: rootSDK,
|
|
sdkConfiguration: sdkConfig,
|
|
hooks: hooks,
|
|
}
|
|
}
|
|
|
|
// GetButlerTasks - Get Butler tasks
|
|
// Returns a list of butler tasks
|
|
func (s *Butler) GetButlerTasks(ctx context.Context, opts ...operations.Option) (*operations.GetButlerTasksResponse, error) {
|
|
o := operations.Options{}
|
|
supportedOptions := []string{
|
|
operations.SupportedOptionRetries,
|
|
operations.SupportedOptionTimeout,
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
if err := opt(&o, supportedOptions...); err != nil {
|
|
return nil, fmt.Errorf("error applying option: %w", err)
|
|
}
|
|
}
|
|
|
|
var baseURL string
|
|
if o.ServerURL == nil {
|
|
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
|
} else {
|
|
baseURL = *o.ServerURL
|
|
}
|
|
opURL, err := url.JoinPath(baseURL, "/butler")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error generating URL: %w", err)
|
|
}
|
|
|
|
hookCtx := hooks.HookContext{
|
|
SDK: s.rootSDK,
|
|
SDKConfiguration: s.sdkConfiguration,
|
|
BaseURL: baseURL,
|
|
Context: ctx,
|
|
OperationID: "getButlerTasks",
|
|
OAuth2Scopes: []string{},
|
|
SecuritySource: s.sdkConfiguration.Security,
|
|
}
|
|
|
|
timeout := o.Timeout
|
|
if timeout == nil {
|
|
timeout = s.sdkConfiguration.Timeout
|
|
}
|
|
|
|
if timeout != nil {
|
|
var cancel context.CancelFunc
|
|
ctx, cancel = context.WithTimeout(ctx, *timeout)
|
|
defer cancel()
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating request: %w", err)
|
|
}
|
|
req.Header.Set("Accept", "application/json")
|
|
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
|
|
|
if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for k, v := range o.SetHeaders {
|
|
req.Header.Set(k, v)
|
|
}
|
|
|
|
globalRetryConfig := s.sdkConfiguration.RetryConfig
|
|
retryConfig := o.Retries
|
|
if retryConfig == nil {
|
|
if globalRetryConfig != nil {
|
|
retryConfig = globalRetryConfig
|
|
}
|
|
}
|
|
|
|
var httpRes *http.Response
|
|
if retryConfig != nil {
|
|
httpRes, err = utils.Retry(ctx, utils.Retries{
|
|
Config: retryConfig,
|
|
StatusCodes: []string{
|
|
"429",
|
|
"500",
|
|
"502",
|
|
"503",
|
|
"504",
|
|
},
|
|
}, func() (*http.Response, error) {
|
|
if req.Body != nil && req.Body != http.NoBody && req.GetBody != nil {
|
|
copyBody, err := req.GetBody()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req.Body = copyBody
|
|
}
|
|
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
|
|
return nil, err
|
|
}
|
|
|
|
return nil, retry.Permanent(err)
|
|
}
|
|
|
|
httpRes, err := s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
}
|
|
return httpRes, err
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
} else {
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
httpRes, err = s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
return nil, err
|
|
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
|
_httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
} else if _httpRes != nil {
|
|
httpRes = _httpRes
|
|
}
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
|
|
res := &operations.GetButlerTasksResponse{
|
|
StatusCode: httpRes.StatusCode,
|
|
ContentType: httpRes.Header.Get("Content-Type"),
|
|
RawResponse: httpRes,
|
|
}
|
|
|
|
switch {
|
|
case httpRes.StatusCode == 200:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out operations.GetButlerTasksResponseBody
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res.Object = &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode == 400:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.GetButlerTasksBadRequest
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode == 401:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.GetButlerTasksUnauthorized
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
// StartAllTasks - Start all Butler tasks
|
|
// This endpoint will attempt to start all Butler tasks that are enabled in the settings. Butler tasks normally run automatically during a time window configured on the server's Settings page but can be manually started using this endpoint. Tasks will run with the following criteria:
|
|
// 1. Any tasks not scheduled to run on the current day will be skipped.
|
|
// 2. If a task is configured to run at a random time during the configured window and we are outside that window, the task will start immediately.
|
|
// 3. If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window.
|
|
// 4. If we are outside the configured window, the task will start immediately.
|
|
func (s *Butler) StartAllTasks(ctx context.Context, opts ...operations.Option) (*operations.StartAllTasksResponse, error) {
|
|
o := operations.Options{}
|
|
supportedOptions := []string{
|
|
operations.SupportedOptionRetries,
|
|
operations.SupportedOptionTimeout,
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
if err := opt(&o, supportedOptions...); err != nil {
|
|
return nil, fmt.Errorf("error applying option: %w", err)
|
|
}
|
|
}
|
|
|
|
var baseURL string
|
|
if o.ServerURL == nil {
|
|
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
|
} else {
|
|
baseURL = *o.ServerURL
|
|
}
|
|
opURL, err := url.JoinPath(baseURL, "/butler")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error generating URL: %w", err)
|
|
}
|
|
|
|
hookCtx := hooks.HookContext{
|
|
SDK: s.rootSDK,
|
|
SDKConfiguration: s.sdkConfiguration,
|
|
BaseURL: baseURL,
|
|
Context: ctx,
|
|
OperationID: "startAllTasks",
|
|
OAuth2Scopes: []string{},
|
|
SecuritySource: s.sdkConfiguration.Security,
|
|
}
|
|
|
|
timeout := o.Timeout
|
|
if timeout == nil {
|
|
timeout = s.sdkConfiguration.Timeout
|
|
}
|
|
|
|
if timeout != nil {
|
|
var cancel context.CancelFunc
|
|
ctx, cancel = context.WithTimeout(ctx, *timeout)
|
|
defer cancel()
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", opURL, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating request: %w", err)
|
|
}
|
|
req.Header.Set("Accept", "application/json")
|
|
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
|
|
|
if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for k, v := range o.SetHeaders {
|
|
req.Header.Set(k, v)
|
|
}
|
|
|
|
globalRetryConfig := s.sdkConfiguration.RetryConfig
|
|
retryConfig := o.Retries
|
|
if retryConfig == nil {
|
|
if globalRetryConfig != nil {
|
|
retryConfig = globalRetryConfig
|
|
}
|
|
}
|
|
|
|
var httpRes *http.Response
|
|
if retryConfig != nil {
|
|
httpRes, err = utils.Retry(ctx, utils.Retries{
|
|
Config: retryConfig,
|
|
StatusCodes: []string{
|
|
"429",
|
|
"500",
|
|
"502",
|
|
"503",
|
|
"504",
|
|
},
|
|
}, func() (*http.Response, error) {
|
|
if req.Body != nil && req.Body != http.NoBody && req.GetBody != nil {
|
|
copyBody, err := req.GetBody()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req.Body = copyBody
|
|
}
|
|
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
|
|
return nil, err
|
|
}
|
|
|
|
return nil, retry.Permanent(err)
|
|
}
|
|
|
|
httpRes, err := s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
}
|
|
return httpRes, err
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
} else {
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
httpRes, err = s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
return nil, err
|
|
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
|
_httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
} else if _httpRes != nil {
|
|
httpRes = _httpRes
|
|
}
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
|
|
res := &operations.StartAllTasksResponse{
|
|
StatusCode: httpRes.StatusCode,
|
|
ContentType: httpRes.Header.Get("Content-Type"),
|
|
RawResponse: httpRes,
|
|
}
|
|
|
|
switch {
|
|
case httpRes.StatusCode == 200:
|
|
case httpRes.StatusCode == 400:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.StartAllTasksBadRequest
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode == 401:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.StartAllTasksUnauthorized
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
// StopAllTasks - Stop all Butler tasks
|
|
// This endpoint will stop all currently running tasks and remove any scheduled tasks from the queue.
|
|
func (s *Butler) StopAllTasks(ctx context.Context, opts ...operations.Option) (*operations.StopAllTasksResponse, error) {
|
|
o := operations.Options{}
|
|
supportedOptions := []string{
|
|
operations.SupportedOptionRetries,
|
|
operations.SupportedOptionTimeout,
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
if err := opt(&o, supportedOptions...); err != nil {
|
|
return nil, fmt.Errorf("error applying option: %w", err)
|
|
}
|
|
}
|
|
|
|
var baseURL string
|
|
if o.ServerURL == nil {
|
|
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
|
} else {
|
|
baseURL = *o.ServerURL
|
|
}
|
|
opURL, err := url.JoinPath(baseURL, "/butler")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error generating URL: %w", err)
|
|
}
|
|
|
|
hookCtx := hooks.HookContext{
|
|
SDK: s.rootSDK,
|
|
SDKConfiguration: s.sdkConfiguration,
|
|
BaseURL: baseURL,
|
|
Context: ctx,
|
|
OperationID: "stopAllTasks",
|
|
OAuth2Scopes: []string{},
|
|
SecuritySource: s.sdkConfiguration.Security,
|
|
}
|
|
|
|
timeout := o.Timeout
|
|
if timeout == nil {
|
|
timeout = s.sdkConfiguration.Timeout
|
|
}
|
|
|
|
if timeout != nil {
|
|
var cancel context.CancelFunc
|
|
ctx, cancel = context.WithTimeout(ctx, *timeout)
|
|
defer cancel()
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating request: %w", err)
|
|
}
|
|
req.Header.Set("Accept", "application/json")
|
|
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
|
|
|
if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for k, v := range o.SetHeaders {
|
|
req.Header.Set(k, v)
|
|
}
|
|
|
|
globalRetryConfig := s.sdkConfiguration.RetryConfig
|
|
retryConfig := o.Retries
|
|
if retryConfig == nil {
|
|
if globalRetryConfig != nil {
|
|
retryConfig = globalRetryConfig
|
|
}
|
|
}
|
|
|
|
var httpRes *http.Response
|
|
if retryConfig != nil {
|
|
httpRes, err = utils.Retry(ctx, utils.Retries{
|
|
Config: retryConfig,
|
|
StatusCodes: []string{
|
|
"429",
|
|
"500",
|
|
"502",
|
|
"503",
|
|
"504",
|
|
},
|
|
}, func() (*http.Response, error) {
|
|
if req.Body != nil && req.Body != http.NoBody && req.GetBody != nil {
|
|
copyBody, err := req.GetBody()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req.Body = copyBody
|
|
}
|
|
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
|
|
return nil, err
|
|
}
|
|
|
|
return nil, retry.Permanent(err)
|
|
}
|
|
|
|
httpRes, err := s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
}
|
|
return httpRes, err
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
} else {
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
httpRes, err = s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
return nil, err
|
|
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
|
_httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
} else if _httpRes != nil {
|
|
httpRes = _httpRes
|
|
}
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
|
|
res := &operations.StopAllTasksResponse{
|
|
StatusCode: httpRes.StatusCode,
|
|
ContentType: httpRes.Header.Get("Content-Type"),
|
|
RawResponse: httpRes,
|
|
}
|
|
|
|
switch {
|
|
case httpRes.StatusCode == 200:
|
|
case httpRes.StatusCode == 400:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.StopAllTasksBadRequest
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode == 401:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.StopAllTasksUnauthorized
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
// StartTask - Start a single Butler task
|
|
// This endpoint will attempt to start a single Butler task that is enabled in the settings. Butler tasks normally run automatically during a time window configured on the server's Settings page but can be manually started using this endpoint. Tasks will run with the following criteria:
|
|
// 1. Any tasks not scheduled to run on the current day will be skipped.
|
|
// 2. If a task is configured to run at a random time during the configured window and we are outside that window, the task will start immediately.
|
|
// 3. If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window.
|
|
// 4. If we are outside the configured window, the task will start immediately.
|
|
func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName, opts ...operations.Option) (*operations.StartTaskResponse, error) {
|
|
request := operations.StartTaskRequest{
|
|
TaskName: taskName,
|
|
}
|
|
|
|
o := operations.Options{}
|
|
supportedOptions := []string{
|
|
operations.SupportedOptionRetries,
|
|
operations.SupportedOptionTimeout,
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
if err := opt(&o, supportedOptions...); err != nil {
|
|
return nil, fmt.Errorf("error applying option: %w", err)
|
|
}
|
|
}
|
|
|
|
var baseURL string
|
|
if o.ServerURL == nil {
|
|
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
|
} else {
|
|
baseURL = *o.ServerURL
|
|
}
|
|
opURL, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error generating URL: %w", err)
|
|
}
|
|
|
|
hookCtx := hooks.HookContext{
|
|
SDK: s.rootSDK,
|
|
SDKConfiguration: s.sdkConfiguration,
|
|
BaseURL: baseURL,
|
|
Context: ctx,
|
|
OperationID: "startTask",
|
|
OAuth2Scopes: []string{},
|
|
SecuritySource: s.sdkConfiguration.Security,
|
|
}
|
|
|
|
timeout := o.Timeout
|
|
if timeout == nil {
|
|
timeout = s.sdkConfiguration.Timeout
|
|
}
|
|
|
|
if timeout != nil {
|
|
var cancel context.CancelFunc
|
|
ctx, cancel = context.WithTimeout(ctx, *timeout)
|
|
defer cancel()
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", opURL, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating request: %w", err)
|
|
}
|
|
req.Header.Set("Accept", "application/json")
|
|
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
|
|
|
if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for k, v := range o.SetHeaders {
|
|
req.Header.Set(k, v)
|
|
}
|
|
|
|
globalRetryConfig := s.sdkConfiguration.RetryConfig
|
|
retryConfig := o.Retries
|
|
if retryConfig == nil {
|
|
if globalRetryConfig != nil {
|
|
retryConfig = globalRetryConfig
|
|
}
|
|
}
|
|
|
|
var httpRes *http.Response
|
|
if retryConfig != nil {
|
|
httpRes, err = utils.Retry(ctx, utils.Retries{
|
|
Config: retryConfig,
|
|
StatusCodes: []string{
|
|
"429",
|
|
"500",
|
|
"502",
|
|
"503",
|
|
"504",
|
|
},
|
|
}, func() (*http.Response, error) {
|
|
if req.Body != nil && req.Body != http.NoBody && req.GetBody != nil {
|
|
copyBody, err := req.GetBody()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req.Body = copyBody
|
|
}
|
|
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
|
|
return nil, err
|
|
}
|
|
|
|
return nil, retry.Permanent(err)
|
|
}
|
|
|
|
httpRes, err := s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
}
|
|
return httpRes, err
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
} else {
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
httpRes, err = s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
return nil, err
|
|
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
|
_httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
} else if _httpRes != nil {
|
|
httpRes = _httpRes
|
|
}
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
|
|
res := &operations.StartTaskResponse{
|
|
StatusCode: httpRes.StatusCode,
|
|
ContentType: httpRes.Header.Get("Content-Type"),
|
|
RawResponse: httpRes,
|
|
}
|
|
|
|
switch {
|
|
case httpRes.StatusCode == 200:
|
|
fallthrough
|
|
case httpRes.StatusCode == 202:
|
|
case httpRes.StatusCode == 400:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.StartTaskBadRequest
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode == 401:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.StartTaskUnauthorized
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
// StopTask - Stop a single Butler task
|
|
// This endpoint will stop a currently running task by name, or remove it from the list of scheduled tasks if it exists. See the section above for a list of task names for this endpoint.
|
|
func (s *Butler) StopTask(ctx context.Context, taskName operations.PathParamTaskName, opts ...operations.Option) (*operations.StopTaskResponse, error) {
|
|
request := operations.StopTaskRequest{
|
|
TaskName: taskName,
|
|
}
|
|
|
|
o := operations.Options{}
|
|
supportedOptions := []string{
|
|
operations.SupportedOptionRetries,
|
|
operations.SupportedOptionTimeout,
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
if err := opt(&o, supportedOptions...); err != nil {
|
|
return nil, fmt.Errorf("error applying option: %w", err)
|
|
}
|
|
}
|
|
|
|
var baseURL string
|
|
if o.ServerURL == nil {
|
|
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
|
} else {
|
|
baseURL = *o.ServerURL
|
|
}
|
|
opURL, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error generating URL: %w", err)
|
|
}
|
|
|
|
hookCtx := hooks.HookContext{
|
|
SDK: s.rootSDK,
|
|
SDKConfiguration: s.sdkConfiguration,
|
|
BaseURL: baseURL,
|
|
Context: ctx,
|
|
OperationID: "stopTask",
|
|
OAuth2Scopes: []string{},
|
|
SecuritySource: s.sdkConfiguration.Security,
|
|
}
|
|
|
|
timeout := o.Timeout
|
|
if timeout == nil {
|
|
timeout = s.sdkConfiguration.Timeout
|
|
}
|
|
|
|
if timeout != nil {
|
|
var cancel context.CancelFunc
|
|
ctx, cancel = context.WithTimeout(ctx, *timeout)
|
|
defer cancel()
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating request: %w", err)
|
|
}
|
|
req.Header.Set("Accept", "application/json")
|
|
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
|
|
|
if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for k, v := range o.SetHeaders {
|
|
req.Header.Set(k, v)
|
|
}
|
|
|
|
globalRetryConfig := s.sdkConfiguration.RetryConfig
|
|
retryConfig := o.Retries
|
|
if retryConfig == nil {
|
|
if globalRetryConfig != nil {
|
|
retryConfig = globalRetryConfig
|
|
}
|
|
}
|
|
|
|
var httpRes *http.Response
|
|
if retryConfig != nil {
|
|
httpRes, err = utils.Retry(ctx, utils.Retries{
|
|
Config: retryConfig,
|
|
StatusCodes: []string{
|
|
"429",
|
|
"500",
|
|
"502",
|
|
"503",
|
|
"504",
|
|
},
|
|
}, func() (*http.Response, error) {
|
|
if req.Body != nil && req.Body != http.NoBody && req.GetBody != nil {
|
|
copyBody, err := req.GetBody()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req.Body = copyBody
|
|
}
|
|
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
|
|
return nil, err
|
|
}
|
|
|
|
return nil, retry.Permanent(err)
|
|
}
|
|
|
|
httpRes, err := s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
}
|
|
return httpRes, err
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
} else {
|
|
req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
httpRes, err = s.sdkConfiguration.Client.Do(req)
|
|
if err != nil || httpRes == nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("error sending request: %w", err)
|
|
} else {
|
|
err = fmt.Errorf("error sending request: no response")
|
|
}
|
|
|
|
_, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
|
|
return nil, err
|
|
} else if utils.MatchStatusCodes([]string{"400", "401", "404", "4XX", "5XX"}, httpRes.StatusCode) {
|
|
_httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
} else if _httpRes != nil {
|
|
httpRes = _httpRes
|
|
}
|
|
} else {
|
|
httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
|
|
res := &operations.StopTaskResponse{
|
|
StatusCode: httpRes.StatusCode,
|
|
ContentType: httpRes.Header.Get("Content-Type"),
|
|
RawResponse: httpRes,
|
|
}
|
|
|
|
switch {
|
|
case httpRes.StatusCode == 200:
|
|
case httpRes.StatusCode == 400:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.StopTaskBadRequest
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode == 401:
|
|
switch {
|
|
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out sdkerrors.StopTaskUnauthorized
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out.RawResponse = httpRes
|
|
return nil, &out
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode == 404:
|
|
fallthrough
|
|
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
|
default:
|
|
rawBody, err := utils.ConsumeRawBody(httpRes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|