mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 10:27:45 +02:00
Merge pull request #594 from anxdpanic/error-responses
update error reporting for custom-api JSON validation
This commit is contained in:
commit
272bf1d2ad
@ -203,6 +203,7 @@ func fetchCustomAPIRequest(ctx context.Context, req *CustomAPIRequest) (*customA
|
||||
body := strings.TrimSpace(string(bodyBytes))
|
||||
|
||||
if !req.SkipJSONValidation && body != "" && !gjson.Valid(body) {
|
||||
if 200 <= resp.StatusCode && resp.StatusCode < 300 {
|
||||
truncatedBody, isTruncated := limitStringLength(body, 100)
|
||||
if isTruncated {
|
||||
truncatedBody += "... <truncated>"
|
||||
@ -212,6 +213,10 @@ func fetchCustomAPIRequest(ctx context.Context, req *CustomAPIRequest) (*customA
|
||||
return nil, errors.New("invalid response JSON")
|
||||
}
|
||||
|
||||
return nil, errors.New(fmt.Sprintf("%d %s", resp.StatusCode, http.StatusText(resp.StatusCode)))
|
||||
|
||||
}
|
||||
|
||||
data := &customAPIResponseData{
|
||||
JSON: decoratedGJSONResult{gjson.Parse(body)},
|
||||
Response: resp,
|
||||
|
Loading…
x
Reference in New Issue
Block a user