requestHook.js 551 B

123456789101112131415161718
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. /**
  4. * 处理wxopenapi返回
  5. *
  6. * @param err
  7. * @param response
  8. * @param body
  9. */
  10. exports.handleWxOpenApiData = (res, err, response, body) => {
  11. // wx.openApi 调用时,需用content-type区分buffer or JSON
  12. const { headers } = response;
  13. let transformRes = res;
  14. if (headers['content-type'] === 'application/json; charset=utf-8') {
  15. transformRes = JSON.parse(transformRes.toString()); // JSON错误时buffer转JSON
  16. }
  17. return transformRes;
  18. };