You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
my interface data format:
return R(status='error', message='端口被占用,请换一个吧', code=200, data={"data": port}).to_json()
When code=200, it is normal. When code=201, the browser network can receive data, but the axios response is undefined. All other interfaces in the project are normal.
To Reproduce
No response
Code snippet
python code:
try:
form_data=request.get_json()print(form_data)port=form_data.get('port',None)ifportis None:
returnR(status='error',message='端口为空!',code=200).to_json()result=scan_ports(config.SSH_HOST_IP,port)ifresultis True:
returnR(status='success',message='端口可用',code=200,data={"data": port}).to_json()elifresultis False:
returnR(status='error',message='端口被占用,请换一个吧',code=201,data={"data": port}).to_json()
except Exceptionase:
current_app.logger.error(f'{e}')returnR(status='error',message='请求失败',code=201).to_json()
vue code:
validateIt(){constt=thist.isLoading=truejiaoyan(t.form).then(res=>{if(res&&res.code===200){t.$message({message: res.message,type: 'success'})t.btnEnable=falset.isLoading=false}else{t.$message({message: res.message,type: 'error'})t.btnEnable=truet.isLoading=false}}).catch(error=>{console.log(error)t.btnEnable=truet.isLoading=falseconsole.log('--------------***************-----------')})Encapsulatedrequests:importaxiosfrom'axios'import{MessageBox,Message}from'element-ui'importstorefrom'@/store'import{getToken}from'@/utils/auth'// 是否显示重新登录exportconstisRelogin={show: false}// create an axios instanceconstservice=axios.create({baseURL: process.env.VUE_APP_BASE_API,// url = base url + request url// withCredentials: true, // send cookies when cross-domain requests 跨域请求发送cookietimeout: 50000// request timeout})// request interceptorservice.interceptors.request.use(config=>{// do something before request is sentif(store.getters.token){// let each request carry token// ['X-Token'] is a custom headers key// please modify it according to the actual situationconfig.headers['Authorization']='Bearer '+getToken()// 让每个请求携带自定义token,原来没有前缀}returnconfig},error=>{// do something with request errorconsole.log(error)// for debugreturnPromise.reject(error)})// response interceptorservice.interceptors.response.use(/** * If you want to get http information such as headers or status * Please return response => response *//** * Determine the request status by custom code * Here is just an example * You can also judge the status by HTTP Status Code */response=>{constres=response.data// const msg = errorCode[res.code] || res.message || errorCode['default']// if the custom code is not 20000, it is judged as an error.if(res.code!==200){// Message({// message: res.message || 'Error',// type: 'error',// duration: 5 * 1000// })// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;if(res.code===50008||res.code===50012||res.code===50014){// to re-loginMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录','系统提示',{confirmButtonText: '重新登录',cancelButtonText: '取消',type: 'warning'}).then(()=>{store.dispatch('user/resetToken').then(()=>{location.reload()})})}// return Promise.reject(new Error(res.message || '后端接口异常'))// eslint-disable-next-line no-unreachableif(response.data.code===401){if(!isRelogin.show){isRelogin.show=trueMessageBox.confirm('登录状态已过期,请重新登录','系统提示',{confirmButtonText: '重新登录',cancelButtonText: '取消',type: 'warning'}).then(()=>{isRelogin.show=false// store.dispatch('logout')this.$router.push('/login')// return Promise.reject(msg)}).catch((status)=>{isRelogin.show=false})}}}else{returnres}},error=>{console.log('err'+error)// for debuglet{ message }=errorif(message==='Network Error'){message='后端接口连接异常'}elseif(message.includes('timeout')){message='系统接口请求超时'}elseif(message.includes('Request failed with status code 401')){message='登录会话超时,请重新登录'}elseif(message.includes('Request failed with status code')){message='系统接口'+message.substr(message.length-3)+'异常'}Message({message: message,type: 'error',duration: 5*1000})returnPromise.reject(error)})exportdefaultservice
Expected behavior
When code=201, the else branch should be used instead of restocking. Res is undefined.
Axios Version
0.18.1
Adapter Version
HTTP
Browser
FireFox
Browser Version
124
Node.js Version
14.9.0
OS
Windows 11
Additional Library Versions
VUE:2
Additional context/Screenshots
No response
The text was updated successfully, but these errors were encountered:
Describe the bug
my interface data format:
return R(status='error', message='端口被占用,请换一个吧', code=200, data={"data": port}).to_json()
When code=200, it is normal. When code=201, the browser network can receive data, but the axios response is undefined. All other interfaces in the project are normal.
To Reproduce
No response
Code snippet
Expected behavior
When code=201, the else branch should be used instead of restocking. Res is undefined.
Axios Version
0.18.1
Adapter Version
HTTP
Browser
FireFox
Browser Version
124
Node.js Version
14.9.0
OS
Windows 11
Additional Library Versions
Additional context/Screenshots
No response
The text was updated successfully, but these errors were encountered: