金币系统前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
646 B

1 month ago
1 month ago
1 month ago
  1. import request from './request'
  2. export default function requestHandler(options) {
  3. const { method = 'get', url, data = {}, params = {}, headers = {} } = options
  4. return request({
  5. method,
  6. url,
  7. data,
  8. params,
  9. headers
  10. })
  11. .then(({ status, data, statusText }) => {
  12. if (status === 200) {
  13. return data
  14. } else {
  15. throw new Error(statusText)
  16. }
  17. })
  18. .catch(error => {
  19. if (error?.needsLogin) {
  20. return { needsLogin: true }
  21. }
  22. return Promise.reject(error)
  23. })
  24. }