import { notification , message as amessage } from 'antd' ; import isUndefined from 'lodash/isUndefined' ; import { BizResponse , ErrorMessageAdapter , BizRedirectHandler , BizDevErrorAdapter , BizErrorMessageAdapter , BizSuccessMessageAdapter , BizNotifyHandler , BizDataAdapter , Message , NotifyMessages , } from '../../types/request' ; const errorMessageAdapter = ( error ) => { const message = error . message ; return { success : false , code : 200 , message , } ; } ; const bizRedirectHandler = ( response ) => { const { data , code } = response ; if ( Number ( code ) === 302 && data && data . redirectUrl ) { window . location . assign ( data . redirectUrl ) ; } } ; const bizDevErrorAdapter = ( response ) => { const { code , success , message , description } = response ; const opCode = Number ( code ) ; if ( success == false && opCode >= 300 && opCode !== 302 ) { return { message : message || `${ code }` , description : description || message , } ; } return null ; } ; const bizErrorMessageAdapter = ( response ) => { const { code , success , message } = response ; const opCode = Number ( code ) ; if ( success === false && ( opCode < 300 || opCode === 302 ) ) { return message ; } return null ; } ; const bizSuccessMessageAdapter = ( response , successMessage ) => { const { success , message } = response ; if ( successMessage === false ) { return null ; } if ( success !== false ) { if ( successMessage === true ) { return message ; } else { return successMessage ; } } return null ; } ; const bizNotifyHandler = ( notifyMessages ) => { const { successMessage , errorMessage , errorDesc } = notifyMessages ; if ( successMessage ) { amessage . success ( successMessage ) ; } else if ( errorMessage ) { amessage . error ( errorMessage ) ; } else if ( errorDesc ) { notification . error ( { message : errorDesc . message , description : errorDesc . description , } ) ; } } ; const bizDataAdapter = ( response ) => { if ( response && ! isUndefined ( response . data ) ) { return response . data ; } return response ; } ; const extendConfig = { errorMessageAdapter , bizDataAdapter , bizDevErrorAdapter , bizErrorMessageAdapter , bizSuccessMessageAdapter , bizNotifyHandler , bizRedirectHandler , } ; export default extendConfig ;