コード例 #1
0
ファイル: apisauce.js プロジェクト: vincent10e/apisauce
const convertResponse = (startedAt, axiosResponse) => {
  const end = RS.toNumber(new Date())
  const duration = (end - startedAt)
  return {
    duration,
    problem: responseToProblem(axiosResponse),
    ok: R.pipe(R.propOr(0, 'status'), in200s)(axiosResponse),
    status: axiosResponse.status || null,
    headers: axiosResponse.headers || null,
    config: axiosResponse.config || null,
    data: axiosResponse.data || null
  }
}
コード例 #2
0
ファイル: apisauce.js プロジェクト: vincent10e/apisauce
const doRequest = (api, axiosRequestConfig) => {
  const {axiosInstance} = api
  const startedAt = RS.toNumber(new Date())

  // first convert the axios response, then execute our callback
  const chain = R.pipe(
    R.partial(convertResponse, [startedAt]),
    R.partial(runMonitors, [api])
  )

  // Make the request and execute the identical pipeline for both promise paths.
  return axiosInstance
    .request(axiosRequestConfig)
    .then(chain)
    .catch(chain)
}