forked from CSGOWTF/csgowtf
#7 added errorPages
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import axios from "axios";
|
||||
import {errorHandling} from "@/utils/Utils";
|
||||
|
||||
const API_URL = process.env.VUE_APP_API_URL
|
||||
|
||||
@@ -9,8 +10,7 @@ export const GetMatches = async () => {
|
||||
if (res.status === 200)
|
||||
return res.data
|
||||
} catch (err) {
|
||||
// TODO: Error handling
|
||||
// console.log(err.response.status, err.response.statusText)
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,9 @@ export const GetUser = async (id) => {
|
||||
const res = await axios.get(`${API_URL}/player/${id}`)
|
||||
|
||||
if (res.status === 200)
|
||||
return [res.status, res.data]
|
||||
return res.data
|
||||
} catch (err) {
|
||||
if (err.response)
|
||||
return [err.response.status, err.response.statusText]
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +58,7 @@ export const TrackMe = async (id64, authcode, sharecode = '') => {
|
||||
statusError = 'Userinput was wrong'
|
||||
status = err.response.status
|
||||
} else {
|
||||
console.log(`${err.response.status}: ${err.response.statusText}`)
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +73,7 @@ export const GetPlayerValue = async (match_id) => {
|
||||
return res.data
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err.response.status, err.response.statusText)
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +85,7 @@ export const GetMatchDetails = async (match_id) => {
|
||||
return res.data
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO: 400, 404
|
||||
console.log(err.response.status, err.response.statusText)
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +97,7 @@ export const LoadMoreMatches = async (player_id, date) => {
|
||||
return res.data
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO: 400, 404
|
||||
console.log(err.response.status, err.response.statusText)
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,8 +110,7 @@ export const GetPlayerMeta = async (player_id, limit = 4) => {
|
||||
return res.data
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO: 400, 404
|
||||
console.log(err.response.status, err.response.statusText)
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,9 +121,8 @@ export const GetWeaponDmg = async (match_id) => {
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
}
|
||||
} catch (e) {
|
||||
// TODO: 400, 404
|
||||
console.log(e)
|
||||
} catch (err) {
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +134,6 @@ export const LoadMoreMatchesExplore = async (date) => {
|
||||
return res.data
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO: 400, 404
|
||||
console.log(err.response.status, err.response.statusText)
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import router from "../router";
|
||||
|
||||
export const GoToMatch = (id) => {
|
||||
router.push({name: 'Match', params: {match_id: id}})
|
||||
router.push({name: 'Match', params: {match_id: id}})
|
||||
}
|
||||
|
||||
export const GoToPlayer = (id) => {
|
||||
router.push({name: 'Player', params: {id: id}})
|
||||
router.push({name: 'Player', params: {id: id}})
|
||||
}
|
||||
|
||||
export const GoToError = (code) => {
|
||||
router.push({name: code})
|
||||
}
|
||||
|
||||
export const GoToLink = (link) => {
|
||||
router.replace(link)
|
||||
router.replace(link)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
import {GoToError} from "@/utils/GoTo";
|
||||
|
||||
export const errorHandling = (code) => {
|
||||
if (code === 404) {
|
||||
GoToError('404')
|
||||
} else if (code === 500) {
|
||||
GoToError('500')
|
||||
} else if (code === 502) {
|
||||
GoToError('502')
|
||||
} else {
|
||||
GoToError('404')
|
||||
}
|
||||
}
|
||||
|
||||
export const setTitle = (title) => {
|
||||
document.title = `${title} | csgoWTF`
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ import {
|
||||
truncate,
|
||||
scrollToPos,
|
||||
StripControlCodes,
|
||||
ProcessName
|
||||
ProcessName,
|
||||
errorHandling
|
||||
} from "./Utils";
|
||||
|
||||
export {
|
||||
@@ -72,5 +73,6 @@ export {
|
||||
LoadMoreMatchesExplore,
|
||||
scrollToPos,
|
||||
StripControlCodes,
|
||||
ProcessName
|
||||
ProcessName,
|
||||
errorHandling
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user