Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2057d40

Browse files
committedMar 13, 2025
chore(internal): codegen related update (#4008)
1 parent 89423be commit 2057d40

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

‎internal/requestconfig/requestconfig.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io"
1111
"math"
1212
"math/rand"
13+
"mime"
1314
"net/http"
1415
"net/url"
1516
"runtime"
@@ -488,7 +489,8 @@ func (cfg *RequestConfig) Execute() (err error) {
488489

489490
// If we are not json, return plaintext
490491
contentType := res.Header.Get("content-type")
491-
isJSON := strings.Contains(contentType, "application/json") || strings.Contains(contentType, "application/vnd.api+json")
492+
mediaType, _, _ := mime.ParseMediaType(contentType)
493+
isJSON := strings.Contains(mediaType, "application/json") || strings.HasSuffix(mediaType, "+json")
492494
if !isJSON {
493495
switch dst := cfg.ResponseBodyInto.(type) {
494496
case *string:
@@ -499,7 +501,7 @@ func (cfg *RequestConfig) Execute() (err error) {
499501
case *[]byte:
500502
*dst = contents
501503
default:
502-
return fmt.Errorf("expected destination type of 'string' or '[]byte' for responses with content-type that is not 'application/json'")
504+
return fmt.Errorf("expected destination type of 'string' or '[]byte' for responses with content-type '%s' that is not 'application/json'", contentType)
503505
}
504506
return nil
505507
}

0 commit comments

Comments
 (0)
Please sign in to comment.