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

@ -43,31 +43,11 @@ type DeleteApi interface {
* content should be achieved through the returned response model if applicable.
*/
PostDeleteExecuteWithHttpInfo(r ApiPostDeleteRequest) (*_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() DeleteApi
// 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() DeleteApi
}
// DeleteApiService DeleteApi service
type DeleteApiService service
func (a *DeleteApiService) OnlyOSS() DeleteApi {
a.isOnlyOSS = true
return a
}
func (a *DeleteApiService) OnlyCloud() DeleteApi {
a.isOnlyCloud = true
return a
}
type ApiPostDeleteRequest struct {
ctx _context.Context
ApiService DeleteApi
@ -227,28 +207,25 @@ func (a *DeleteApiService) PostDeleteExecuteWithHttpInfo(r ApiPostDeleteRequest)
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 Error
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))