feat: improved error messages for cloud- or oss-only commands (#140)
* feat: set logging info for cloud- or oss-only commands * fix: add cloud-only to BucketSchemasApi * fix: api-only flagging and %w for return error wrapping * fix: keep the model assignment
This commit is contained in:
@ -12,6 +12,7 @@ package api
|
||||
|
||||
import (
|
||||
_context "context"
|
||||
_fmt "fmt"
|
||||
_ioutil "io/ioutil"
|
||||
_nethttp "net/http"
|
||||
_neturl "net/url"
|
||||
@ -35,11 +36,31 @@ type WriteApi interface {
|
||||
* PostWriteExecute executes the request
|
||||
*/
|
||||
PostWriteExecute(r ApiPostWriteRequest) error
|
||||
|
||||
// Sets additional descriptive text in the error message if any request in
|
||||
// this API fails, indicating that it is intended to be used only on OSS
|
||||
// servers.
|
||||
OnlyOSS() WriteApi
|
||||
|
||||
// Sets additional descriptive text in the error message if any request in
|
||||
// this API fails, indicating that it is intended to be used only on cloud
|
||||
// servers.
|
||||
OnlyCloud() WriteApi
|
||||
}
|
||||
|
||||
// WriteApiService WriteApi service
|
||||
type WriteApiService service
|
||||
|
||||
func (a *WriteApiService) OnlyOSS() WriteApi {
|
||||
a.isOnlyOSS = true
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *WriteApiService) OnlyCloud() WriteApi {
|
||||
a.isOnlyCloud = true
|
||||
return a
|
||||
}
|
||||
|
||||
type ApiPostWriteRequest struct {
|
||||
ctx _context.Context
|
||||
ApiService WriteApi
|
||||
@ -235,68 +256,80 @@ func (a *WriteApiService) PostWriteExecute(r ApiPostWriteRequest) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var errorPrefix string
|
||||
if a.isOnlyOSS {
|
||||
errorPrefix = "InfluxDB OSS-only command failed: "
|
||||
} else if a.isOnlyCloud {
|
||||
errorPrefix = "InfluxDB Cloud-only command failed: "
|
||||
}
|
||||
|
||||
if localVarHTTPResponse.StatusCode >= 300 {
|
||||
body, err := GunzipIfNeeded(localVarHTTPResponse)
|
||||
if err != nil {
|
||||
body.Close()
|
||||
return err
|
||||
return _fmt.Errorf("%s%w", errorPrefix, err)
|
||||
}
|
||||
localVarBody, err := _ioutil.ReadAll(body)
|
||||
body.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
return _fmt.Errorf("%s%w", errorPrefix, err)
|
||||
}
|
||||
newErr := GenericOpenAPIError{
|
||||
body: localVarBody,
|
||||
error: localVarHTTPResponse.Status,
|
||||
error: _fmt.Sprintf("%s%s", errorPrefix, localVarHTTPResponse.Status),
|
||||
}
|
||||
if localVarHTTPResponse.StatusCode == 400 {
|
||||
var v LineProtocolError
|
||||
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
||||
if err != nil {
|
||||
newErr.error = err.Error()
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, err.Error())
|
||||
return newErr
|
||||
}
|
||||
newErr.model = &v
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, v.Error())
|
||||
return newErr
|
||||
}
|
||||
if localVarHTTPResponse.StatusCode == 401 {
|
||||
var v Error
|
||||
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
||||
if err != nil {
|
||||
newErr.error = err.Error()
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, err.Error())
|
||||
return newErr
|
||||
}
|
||||
newErr.model = &v
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, v.Error())
|
||||
return newErr
|
||||
}
|
||||
if localVarHTTPResponse.StatusCode == 403 {
|
||||
var v Error
|
||||
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
||||
if err != nil {
|
||||
newErr.error = err.Error()
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, err.Error())
|
||||
return newErr
|
||||
}
|
||||
newErr.model = &v
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, v.Error())
|
||||
return newErr
|
||||
}
|
||||
if localVarHTTPResponse.StatusCode == 413 {
|
||||
var v LineProtocolLengthError
|
||||
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
||||
if err != nil {
|
||||
newErr.error = err.Error()
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, err.Error())
|
||||
return newErr
|
||||
}
|
||||
newErr.model = &v
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, v.Error())
|
||||
return newErr
|
||||
}
|
||||
var v Error
|
||||
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
||||
if err != nil {
|
||||
newErr.error = err.Error()
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, err.Error())
|
||||
return newErr
|
||||
}
|
||||
newErr.model = &v
|
||||
newErr.error = _fmt.Sprintf("%s%v", errorPrefix, v.Error())
|
||||
return newErr
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user