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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ namespace Actions {
|
||||
return res
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('error=', error)
|
||||
console.log('error dbLoadTodo', error)
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return error
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ import { GlobalStore, UserStore, Todos } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
|
||||
import translate from './../../globalroutines/util'
|
||||
import * as Types from "@src/store/Api/ApiTypes"
|
||||
|
||||
const bcrypt = require('bcryptjs')
|
||||
|
||||
@@ -150,11 +151,11 @@ namespace Mutations {
|
||||
}
|
||||
|
||||
|
||||
function setErrorCatch(state: IUserState, err: number) {
|
||||
function setErrorCatch(state: IUserState, axerr: Types.AxiosError) {
|
||||
if (state.servercode !== rescodes.ERR_SERVERFETCH) {
|
||||
state.servercode = err
|
||||
state.servercode = axerr.getCode()
|
||||
}
|
||||
console.log('Err catch: (servercode:', err, ')')
|
||||
console.log('Err catch: (servercode:', axerr.getCode(), axerr.getMsgError(), ')')
|
||||
}
|
||||
|
||||
function getMsgError(state: IUserState, err: number) {
|
||||
@@ -224,9 +225,9 @@ namespace Actions {
|
||||
.then(res => {
|
||||
return { code: res.data.code, msg: res.data.msg }
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch((error: Types.AxiosError) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return { code: UserStore.getters.getServerCode, msg: error }
|
||||
return { code: UserStore.getters.getServerCode, msg: error.getMsgError() }
|
||||
})
|
||||
|
||||
}
|
||||
@@ -351,9 +352,9 @@ namespace Actions {
|
||||
}
|
||||
|
||||
async function signin(context, authData: ISigninOptions) {
|
||||
console.log('LOGIN ')
|
||||
console.log('LOGIN signin')
|
||||
|
||||
console.log('MYLANG = ' + state.lang)
|
||||
// console.log('MYLANG = ' + state.lang)
|
||||
|
||||
let sub = null
|
||||
|
||||
@@ -361,6 +362,7 @@ namespace Actions {
|
||||
if ('serviceWorker' in navigator) {
|
||||
sub = await navigator.serviceWorker.ready
|
||||
.then(function (swreg) {
|
||||
console.log('swreg')
|
||||
let sub = swreg.pushManager.getSubscription()
|
||||
return sub
|
||||
})
|
||||
@@ -388,19 +390,19 @@ namespace Actions {
|
||||
options
|
||||
}
|
||||
|
||||
// console.log('PASSO 4')
|
||||
|
||||
console.log(usertosend)
|
||||
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
let myres: any
|
||||
|
||||
console.log('Api.SendReq')
|
||||
|
||||
return Api.SendReq('/users/login', 'POST', usertosend, true)
|
||||
.then(res => {
|
||||
myres = res
|
||||
if (myres.data.code === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
Mutations.mutations.setServerCode(myres.data.code)
|
||||
return myres
|
||||
}
|
||||
|
||||
if (myres.status !== 200) {
|
||||
return Promise.reject(rescodes.ERR_GENERICO)
|
||||
@@ -512,7 +514,7 @@ namespace Actions {
|
||||
// console.log('*** autologin_FromLocalStorage ***')
|
||||
// INIT
|
||||
|
||||
UserStore.state.lang = localStorage.getItem(rescodes.localStorage.lang)
|
||||
UserStore.state.lang = rescodes.getItemLS(rescodes.localStorage.lang)
|
||||
|
||||
const token = localStorage.getItem(rescodes.localStorage.token)
|
||||
if (!token) {
|
||||
|
||||
@@ -21,7 +21,7 @@ export const rescodes = {
|
||||
userId: 'uid',
|
||||
token: 'tk',
|
||||
username: 'uname',
|
||||
lang:'lg'
|
||||
lang: 'lg'
|
||||
},
|
||||
|
||||
Todos: {
|
||||
@@ -247,6 +247,14 @@ export const rescodes = {
|
||||
|
||||
jsonCopy(src) {
|
||||
return JSON.parse(JSON.stringify(src))
|
||||
},
|
||||
|
||||
getItemLS(item) {
|
||||
let ris = localStorage.getItem(item)
|
||||
if ((ris == null) || (ris === '') || (ris === 'null'))
|
||||
ris = ''
|
||||
|
||||
return ris
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user