improve: Drag & Drop (work in progress)
fix: - Axios: login error msg
This commit is contained in:
@@ -13,14 +13,16 @@ export class AxiosSuccess {
|
||||
|
||||
export class AxiosError {
|
||||
public success: boolean = false
|
||||
public status: number
|
||||
public status: number = 0
|
||||
public data: any
|
||||
public code: any
|
||||
public code: any = 0
|
||||
public msgerr: string = ''
|
||||
|
||||
constructor(status: number, data?: any, code?: any) {
|
||||
constructor(status: number, data?: any, code?: any, msgerr?: string) {
|
||||
this.status = status
|
||||
this.data = data
|
||||
this.code = code
|
||||
this.msgerr = msgerr
|
||||
if (status !== 401) {
|
||||
// if (status == 0) message = 'Vérifiez votre connexion Internet';
|
||||
// NotificationsStore.actions.addNotification({ type: 'warning', message: message })
|
||||
@@ -31,6 +33,22 @@ export class AxiosError {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getMsgError() {
|
||||
if (this.data && this.data.error)
|
||||
return this.data.error.message
|
||||
|
||||
return this.msgerr
|
||||
}
|
||||
public getCode() {
|
||||
if (this.code === 0) {
|
||||
if (this.data.code) {
|
||||
return this.data.code
|
||||
}
|
||||
}
|
||||
|
||||
return this.code
|
||||
}
|
||||
}
|
||||
|
||||
// export class ApiResponse {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios'
|
||||
// import LoginModule from '../Modules/Auth/LoginStore'
|
||||
import router from '@router'
|
||||
import {clone} from 'lodash'
|
||||
import { clone } from 'lodash'
|
||||
import * as Types from './ApiTypes'
|
||||
import { GlobalStore, UserStore } from '@store'
|
||||
import { rescodes } from '@src/store/Modules/rescodes'
|
||||
@@ -21,8 +21,10 @@ axiosInstance.interceptors.response.use(
|
||||
return response
|
||||
},
|
||||
(error) => {
|
||||
console.log(error.response.status)
|
||||
console.log('Request Error: ', error.response)
|
||||
if (error.response) {
|
||||
console.log(error.response.status)
|
||||
console.log('Request Error: ', error.response)
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
@@ -48,11 +50,12 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
|
||||
}
|
||||
})
|
||||
ricevuto = true
|
||||
console.log('response', response)
|
||||
// console.log(new Types.AxiosSuccess(response.data, response.status))
|
||||
|
||||
const setAuthToken = (path === '/updatepwd')
|
||||
|
||||
if (response.status === 200) {
|
||||
if (response && (response.status === 200)) {
|
||||
let x_auth_token = ''
|
||||
try {
|
||||
if (setAuthToken || (path === '/users/login')) {
|
||||
@@ -87,7 +90,8 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
|
||||
// @ts-ignore
|
||||
response = await axiosInstance[type](path, {
|
||||
params: payload,
|
||||
headers: {'Content-Type': 'application/json',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-auth': UserStore.state.x_auth_token
|
||||
}
|
||||
})
|
||||
@@ -104,18 +108,28 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
|
||||
}
|
||||
catch (error) {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROR using', path, error, 'ricevuto=', ricevuto)
|
||||
console.log('ERROR using', path)
|
||||
// console.log('Error received: ', error)
|
||||
// console.log('ricevuto=', ricevuto)
|
||||
console.log('error.response=', error.response)
|
||||
}
|
||||
let mycode = 0
|
||||
if (!ricevuto) {
|
||||
mycode = rescodes.ERR_SERVERFETCH
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_SERVERFETCH)
|
||||
} else {
|
||||
mycode = rescodes.ERR_GENERICO
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
}
|
||||
|
||||
if (error.response) {
|
||||
return Promise.reject(new Types.AxiosError(error.response.status, error.response.data))
|
||||
if (error.response.data && error.response.data.code) {
|
||||
mycode = error.response.data.code
|
||||
UserStore.mutations.setServerCode(mycode)
|
||||
}
|
||||
return Promise.reject(new Types.AxiosError(error.response.status, error.response.data, error.response.data.code))
|
||||
} else {
|
||||
return Promise.reject(new Types.AxiosError(0))
|
||||
return Promise.reject(new Types.AxiosError(0, null, mycode, error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user