Commit 00bf316 1 parent 324ffef commit 00bf316 Copy full SHA for 00bf316
File tree 2 files changed +47
-1
lines changed
2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { isPlainObject } from "./is-plain-object.js";
3
3
import { RequestError } from "@octokit/request-error" ;
4
4
import type { EndpointInterface , OctokitResponse } from "@octokit/types" ;
5
5
6
+ type ContentType = ReturnType < typeof safeParse > ;
7
+
6
8
export default async function fetchWrapper (
7
9
requestOptions : ReturnType < EndpointInterface > ,
8
10
) : Promise < OctokitResponse < any > > {
@@ -155,7 +157,7 @@ async function getResponseData(response: Response): Promise<any> {
155
157
156
158
const mimetype = safeParse ( contentType ) ;
157
159
158
- if ( mimetype . type === "application/json" ) {
160
+ if ( isJSONResponse ( mimetype ) ) {
159
161
let text = "" ;
160
162
try {
161
163
text = await response . text ( ) ;
@@ -173,6 +175,13 @@ async function getResponseData(response: Response): Promise<any> {
173
175
}
174
176
}
175
177
178
+ function isJSONResponse ( mimetype : ContentType ) : boolean {
179
+ return (
180
+ mimetype . type === "application/json" ||
181
+ mimetype . type === "application/scim+json"
182
+ ) ;
183
+ }
184
+
176
185
function toErrorMessage ( data : string | ArrayBuffer | Record < string , unknown > ) {
177
186
if ( typeof data === "string" ) {
178
187
return data ;
Original file line number Diff line number Diff line change @@ -1263,4 +1263,41 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
1263
1263
} ) ,
1264
1264
) . rejects . toHaveProperty ( "message" , "Unknown error: {}" ) ;
1265
1265
} ) ;
1266
+
1267
+ it ( "parses response bodies as JSON when Content-Type is application/scim+json" , async ( ) => {
1268
+ expect . assertions ( 1 ) ;
1269
+
1270
+ const mock = fetchMock . createInstance ( ) ;
1271
+ mock . get ( "https://api.github.com/scim/v2/Users" , {
1272
+ status : 200 ,
1273
+ body : {
1274
+ totalResults : 1 ,
1275
+ Resources : [
1276
+ {
1277
+ id : "123" ,
1278
+ userName : "octocat" ,
1279
+ } ,
1280
+ ] ,
1281
+ } ,
1282
+ headers : {
1283
+ "Content-Type" : "application/scim+json" ,
1284
+ } ,
1285
+ } ) ;
1286
+
1287
+ const response = await request ( "GET /scim/v2/Users" , {
1288
+ request : {
1289
+ fetch : mock . fetchHandler ,
1290
+ } ,
1291
+ } ) ;
1292
+
1293
+ expect ( response . data ) . toEqual ( {
1294
+ totalResults : 1 ,
1295
+ Resources : [
1296
+ {
1297
+ id : "123" ,
1298
+ userName : "octocat" ,
1299
+ } ,
1300
+ ] ,
1301
+ } ) ;
1302
+ } ) ;
1266
1303
} ) ;
You can’t perform that action at this time.
0 commit comments