fix response

This commit is contained in:
Simon Larsen 2022-08-14 09:24:49 +01:00
parent 0696fb7d29
commit d6941e6bdd
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
2 changed files with 5 additions and 3 deletions

View File

@ -7,8 +7,8 @@ describe('Response()', () => {
responseObject = new Response(200, { welcome: 'here' });
expect(responseObject.statusCode).toBe(200);
expect(responseObject.data).toEqual({ welcome: 'here' });
responseObject = new Response(200, [{ welcome: 'here' }]);
expect(responseObject.statusCode).toBe(200);
expect(responseObject.data).toEqual([{ welcome: 'here' }]);
let responseObjectArray = new Response<Array<JSONObject>>(200, [{ welcome: 'here' }]);
expect(responseObjectArray.statusCode).toBe(200);
expect(responseObjectArray.data).toEqual([{ welcome: 'here' }]);
});
});

View File

@ -76,6 +76,8 @@ export default class HTTPResponse<
this.jsonData = JSONFunctions.deserializeArray(
data['data'] as JSONArray
);
} else if(Array.isArray(data)) {
this.jsonData = JSONFunctions.deserializeArray(data as JSONArray);
} else {
this.jsonData = JSONFunctions.deserialize(data as JSONObject);
}