* Processes an HTTP response into a WebAPICallResult by performing JSON parsing on the body and merging relevent * HTTP headers into the object. * @param response - an http response
(response: AxiosResponse)
| 712 | * @param response - an http response |
| 713 | */ |
| 714 | private buildResult(response: AxiosResponse): WebAPICallResult { |
| 715 | const data = response.data; |
| 716 | |
| 717 | if (data.response_metadata === undefined) { |
| 718 | data.response_metadata = {}; |
| 719 | } |
| 720 | |
| 721 | // add scopes metadata from headers |
| 722 | if (response.headers['x-oauth-scopes'] !== undefined) { |
| 723 | data.response_metadata.scopes = (response.headers['x-oauth-scopes'] as string).trim().split(/\s*,\s*/); |
| 724 | } |
| 725 | if (response.headers['x-accepted-oauth-scopes'] !== undefined) { |
| 726 | data.response_metadata.acceptedScopes = |
| 727 | (response.headers['x-accepted-oauth-scopes'] as string).trim().split(/\s*,\s*/); |
| 728 | } |
| 729 | |
| 730 | // add retry metadata from headers |
| 731 | const retrySec = parseRetryHeaders(response); |
| 732 | if (retrySec !== undefined) { |
| 733 | data.response_metadata.retryAfter = retrySec; |
| 734 | } |
| 735 | |
| 736 | return data; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | export default WebClient; |
no test coverage detected