feat(api): add nicer error message to format issues indicating permission denied
All checks were successful
test / test (push) Successful in 42s
All checks were successful
test / test (push) Successful in 42s
This commit is contained in:
parent
ece2955a2a
commit
2909e0d1b4
2 changed files with 10 additions and 1 deletions
|
|
@ -213,6 +213,10 @@ func (c *Client) parseStreamingAppInstanceResponse(resp *http.Response, result i
|
|||
var errorMessage string
|
||||
|
||||
parseErr := sdkhttp.ParseJSONLines(resp.Body, func(line []byte) error {
|
||||
// On permission denied, Edge API returns just an empty array []!
|
||||
if len(line) == 0 || line[0] == '[' {
|
||||
return fmt.Errorf("%w", ErrFaultyResponsePerhaps403)
|
||||
}
|
||||
// Try parsing as ResultResponse first (error format)
|
||||
var resultResp ResultResponse
|
||||
if err := json.Unmarshal(line, &resultResp); err == nil && resultResp.Result.Message != "" {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ import (
|
|||
|
||||
var (
|
||||
// ErrResourceNotFound indicates the requested resource was not found
|
||||
ErrResourceNotFound = fmt.Errorf("resource not found")
|
||||
ErrResourceNotFound = fmt.Errorf("resource not found")
|
||||
ErrFaultyResponsePerhaps403 = fmt.Errorf("faulty response from API, may indicate permission denied")
|
||||
)
|
||||
|
||||
// CreateApp creates a new application in the specified region
|
||||
|
|
@ -179,6 +180,10 @@ func (c *Client) parseStreamingResponse(resp *http.Response, result interface{})
|
|||
var responses []Response[App]
|
||||
|
||||
parseErr := sdkhttp.ParseJSONLines(resp.Body, func(line []byte) error {
|
||||
// On permission denied, Edge API returns just an empty array []!
|
||||
if len(line) == 0 || line[0] == '[' {
|
||||
return fmt.Errorf("%w", ErrFaultyResponsePerhaps403)
|
||||
}
|
||||
var response Response[App]
|
||||
if err := json.Unmarshal(line, &response); err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue