feat: enhanced error messages for cloud and oss specific commands (#347)

* feat: enhanced error messages for cloud and oss specific commands

* chore: rename test
This commit is contained in:
William Baker
2021-12-28 10:03:29 -05:00
committed by GitHub
parent 13d0827815
commit 7af0b2ae73
36 changed files with 1503 additions and 1985 deletions

View File

@ -61,31 +61,11 @@ type WriteApi interface {
* content should be achieved through the returned response model if applicable.
*/
PostWriteExecuteWithHttpInfo(r ApiPostWriteRequest) (*_nethttp.Response, 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
@ -313,28 +293,25 @@ func (a *WriteApiService) PostWriteExecuteWithHttpInfo(r ApiPostWriteRequest) (*
return localVarHTTPResponse, err
}
var errorPrefix string
if a.isOnlyOSS {
errorPrefix = "InfluxDB OSS-only command failed: "
} else if a.isOnlyCloud {
errorPrefix = "InfluxDB Cloud-only command failed: "
newErr := GenericOpenAPIError{
buildHeader: localVarHTTPResponse.Header.Get("X-Influxdb-Build"),
}
if localVarHTTPResponse.StatusCode >= 300 {
body, err := GunzipIfNeeded(localVarHTTPResponse)
if err != nil {
body.Close()
return localVarHTTPResponse, _fmt.Errorf("%s%w", errorPrefix, err)
newErr.error = err.Error()
return localVarHTTPResponse, newErr
}
localVarBody, err := _io.ReadAll(body)
body.Close()
if err != nil {
return localVarHTTPResponse, _fmt.Errorf("%s%w", errorPrefix, err)
}
newErr := GenericOpenAPIError{
body: localVarBody,
error: _fmt.Sprintf("%s%s", errorPrefix, localVarHTTPResponse.Status),
newErr.error = err.Error()
return localVarHTTPResponse, newErr
}
newErr.body = localVarBody
newErr.error = localVarHTTPResponse.Status
if localVarHTTPResponse.StatusCode == 400 {
var v LineProtocolError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))