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.

27 lines
668 B

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