Verejna cast, hezci 404ka, refaktoring
This commit is contained in:
+21
-3
@@ -3,7 +3,8 @@ import {createApolloProvider} from "@vue/apollo-option";
|
||||
import {createUploadLink} from 'apollo-upload-client';
|
||||
import {onError} from "@apollo/client/link/error";
|
||||
import {useUserStore} from "stores/User";
|
||||
import {useRouter} from "vue-router";
|
||||
import {useRoute, useRouter} from "vue-router";
|
||||
import {useAppStore} from "stores/App";
|
||||
|
||||
|
||||
const uploadLink = createUploadLink({
|
||||
@@ -15,7 +16,7 @@ const errorLink = onError(
|
||||
if (networkError?.statusCode === 401) {
|
||||
return fromPromise(
|
||||
useUserStore().refreshAccessToken().catch((error) => {
|
||||
useRouter().push({to: "login"});
|
||||
useAppStore().appStatus = 401;
|
||||
})
|
||||
)
|
||||
.filter((value) => Boolean(value))
|
||||
@@ -32,6 +33,21 @@ const errorLink = onError(
|
||||
return forward(operation);
|
||||
});
|
||||
}
|
||||
|
||||
if (graphQLErrors) {
|
||||
const messages = [];
|
||||
|
||||
for (const error of graphQLErrors) {
|
||||
if (error.message === "Not found") {
|
||||
useAppStore().appStatus = 404;
|
||||
}
|
||||
|
||||
if (error.message === "Not authenticated") {
|
||||
window.location = "/login";
|
||||
}
|
||||
}
|
||||
console.log(graphQLErrors)
|
||||
}
|
||||
});
|
||||
|
||||
const authLink = new ApolloLink((operation, forward) => {
|
||||
@@ -60,7 +76,9 @@ export const apolloWrapper = {
|
||||
})
|
||||
.then((response) => response)
|
||||
.catch(err => {
|
||||
console.error("Error during query: ", err)
|
||||
console.log(err.message);
|
||||
// console.error("Error during query: ", err)
|
||||
return err;
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import gql from "graphql-tag";
|
||||
|
||||
export const FRAGMENT_AIRPORT_INFO = gql`
|
||||
fragment airportInfo on Airport {
|
||||
id
|
||||
name
|
||||
icaoCode
|
||||
gpsLatitude
|
||||
|
||||
@@ -37,6 +37,11 @@ fragment flightFullInfo on Flight {
|
||||
...airportInfo
|
||||
}
|
||||
|
||||
copilot {
|
||||
id
|
||||
name
|
||||
}
|
||||
|
||||
gpxTrackUrl
|
||||
track {
|
||||
pointOfInterest {
|
||||
@@ -103,15 +108,3 @@ ${FRAGMENT_AIRPORT_INFO}
|
||||
${FRAGMENT_AIRCRAFT_BASIC_INFO}
|
||||
`
|
||||
|
||||
export const FRAGMENT_FLIGHT_EDIT_IDS = gql`
|
||||
fragment flightEditIds on Flight {
|
||||
landingAirportId
|
||||
takeoffAirportId
|
||||
aircraftId
|
||||
copilotId
|
||||
copilot {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import gql from "graphql-tag";
|
||||
import {FRAGMENT_FLIGHT_EDIT_IDS, FRAGMENT_FLIGHT_FULL_INFO, FRAGMENT_FLIGHT_LIST_INFO} from "src/graphql/fragments/flight";
|
||||
import {FRAGMENT_FLIGHT_FULL_INFO, FRAGMENT_FLIGHT_LIST_INFO} from "src/graphql/fragments/flight";
|
||||
|
||||
export const FLIGHTS_LIST = gql`
|
||||
query FlightsList {
|
||||
@@ -14,11 +14,9 @@ export const FLIGHT_DETAIL = gql`
|
||||
query FlightDetail($id: Int!) {
|
||||
flight(id: $id) {
|
||||
...flightFullInfo
|
||||
...flightEditIds
|
||||
}
|
||||
}
|
||||
|
||||
${FRAGMENT_FLIGHT_FULL_INFO}
|
||||
${FRAGMENT_FLIGHT_EDIT_IDS}
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user