Ver 0.2.8
Added msg Server error in every pages Nuovo Gruppo non funziona. Corretto altre funzioni del Gruppo Errore del server" Network Error", fare pagina test con altri host per vedere se da lo stesso msg, con IP
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import axios, { AxiosInstance, AxiosResponse } from 'axios'
|
||||
// import LoginModule from '../Modules/Auth/LoginStore'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import { toolsext } from '@src/store/Modules/toolsext'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import * as Types from './ApiTypes'
|
||||
|
||||
export const API_URL = process.env.MONGODB_HOST
|
||||
export let API_URL = process.env.MONGODB_HOST
|
||||
export const axiosInstance: AxiosInstance = axios.create({
|
||||
baseURL: API_URL,
|
||||
headers: {
|
||||
@@ -48,6 +48,7 @@ export const removeAuthHeaders = () => {
|
||||
}
|
||||
|
||||
async function Request(type: string, path: string, payload: any): Promise<Types.AxiosSuccess | Types.AxiosError | undefined> {
|
||||
|
||||
let ricevuto = false
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
@@ -56,6 +57,7 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
|
||||
let response: AxiosResponse
|
||||
if (type === 'post' || type === 'put' || type === 'patch') {
|
||||
response = await axiosInstance[type](path, payload, {
|
||||
baseURL: globalStore.getServerHost(),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-auth': userStore.x_auth_token,
|
||||
@@ -103,6 +105,7 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
|
||||
} if (type === 'get' || type === 'delete') {
|
||||
// @ts-ignore
|
||||
response = await axiosInstance[type](path, {
|
||||
baseURL: globalStore.getServerHost(),
|
||||
params: payload,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -113,6 +116,7 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
|
||||
return new Types.AxiosSuccess(response.data, response.status)
|
||||
} if (type === 'postFormData') {
|
||||
response = await axiosInstance.post(path, payload, {
|
||||
baseURL: globalStore.getServerHost(),
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
'x-auth': userStore.x_auth_token,
|
||||
|
||||
@@ -1201,6 +1201,18 @@ export const tools = {
|
||||
],
|
||||
},
|
||||
|
||||
getServerHost() {
|
||||
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
if (globalStore.serverHost) {
|
||||
return globalStore.serverHost
|
||||
} else {
|
||||
return process.env.MONGODB_HOST
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getTitlePriority(priority: number): string {
|
||||
let cl = ''
|
||||
|
||||
@@ -3384,7 +3396,7 @@ export const tools = {
|
||||
}
|
||||
},
|
||||
geturlupload() {
|
||||
return process.env.MONGODB_HOST + `/uploadnew/${this.getvers()}/`
|
||||
return tools.getServerHost() + `/uploadnew/${this.getvers()}/`
|
||||
},
|
||||
escapeslash(mystr: string) {
|
||||
return mystr.replace(/\//g, '-')
|
||||
@@ -4398,7 +4410,7 @@ export const tools = {
|
||||
|
||||
async registeredemail(email: string) {
|
||||
|
||||
const VALIDATE_USER_URL = process.env.MONGODB_HOST + '/email/ck'
|
||||
const VALIDATE_USER_URL = tools.getServerHost() + '/email/ck'
|
||||
|
||||
let onSuccess = (res: AxiosResponse) => {
|
||||
return res.status !== PayloadMessageTypes.statusfound
|
||||
@@ -5005,7 +5017,7 @@ export const tools = {
|
||||
return 'mywork'
|
||||
} else if (table === toolsext.TABMYBACHECAS) {
|
||||
return 'mypage'
|
||||
} else if (table === 'mygroups') {
|
||||
} else if (table === toolsext.TABMYGROUPS) {
|
||||
return 'grp'
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
rightDrawerOpen: false,
|
||||
rightCartOpen: false,
|
||||
stateConnection: stateConnDefault,
|
||||
serverError: false,
|
||||
serverMsgError: {},
|
||||
networkDataReceived: false,
|
||||
clickcmd: '',
|
||||
cfgServer: [],
|
||||
@@ -778,10 +780,13 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
|
||||
return Api.SendReq('/gettable', 'POST', params)
|
||||
.then((res) => {
|
||||
this.serverError = false
|
||||
// console.table(res)
|
||||
return res.data
|
||||
})
|
||||
.catch((error) => {
|
||||
this.serverError = true
|
||||
this.serverMsgError = error
|
||||
console.log('error loadTable', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return null
|
||||
@@ -1228,7 +1233,9 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
return Api.SendReq(`/loadsite/${myuserid}/${process.env.APP_ID}/${process.env.APP_VERSION}`, 'GET', null)
|
||||
.then((res) => {
|
||||
console.log('____________________________ res', res)
|
||||
this.serverError = false
|
||||
if (res.status === 200) {
|
||||
|
||||
calendarStore.bookedevent = (res.data.bookedevent) ? res.data.bookedevent : []
|
||||
calendarStore.eventlist = (res.data.eventlist) ? res.data.eventlist : []
|
||||
calendarStore.operators = (res.data.operators) ? res.data.operators : []
|
||||
@@ -1304,6 +1311,8 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
}).then((res) => res).catch((error) => {
|
||||
console.log('error dbLoad', error)
|
||||
// userStore.setErrorCatch(error)
|
||||
this.serverError = true
|
||||
this.serverMsgError = error
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
},
|
||||
@@ -1432,5 +1441,35 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
return myarr
|
||||
},
|
||||
|
||||
getMsgServerError() {
|
||||
if (this.serverError) {
|
||||
if (this.serverMsgError) {
|
||||
if (this.serverMsgError.status === 500) {
|
||||
return 'Errore Interno del Server'
|
||||
} else if (this.serverMsgError.msgerr === '') {
|
||||
return 'Codice Errore ' + this.serverMsgError.status
|
||||
}
|
||||
try {
|
||||
return this.serverMsgError.msgerr.message
|
||||
}catch (e) {
|
||||
return this.serverMsgError.msgerr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
},
|
||||
|
||||
getServerHost() {
|
||||
|
||||
if (this.serverHost) {
|
||||
return this.serverHost
|
||||
} else {
|
||||
return process.env.MONGODB_HOST
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user