-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from metrico/jacovinus-fix-labels
network alerts fix
- Loading branch information
Showing
40 changed files
with
3,876 additions
and
3,676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,69 @@ | ||
export const errorHandler = (url, error) => { | ||
const { request, response } = error; | ||
|
||
if (response?.statusText) { | ||
const status = response?.status; | ||
return { | ||
message: "API " + response.statusText + ", Please adjust API URL", | ||
status, | ||
}; | ||
} else if (!url.includes(window.location.protocol)) { | ||
return { | ||
message: "Mixed Content Error, your View should be over same protocol as your API", | ||
status: 500, | ||
}; | ||
} else if (request) { | ||
if(error.stack.includes('Network Error')) { | ||
return { | ||
message: "Invalid API URL, please adjust API URL",status:500 | ||
} | ||
} | ||
return { | ||
message: "server time out", | ||
status: response?.status, | ||
}; | ||
} else if (error.stack.includes("Invalid URL")) { | ||
return { | ||
message: "Invalid API URL, please adjust API URL", | ||
stauts: response?.status, | ||
}; | ||
} else if (error?.response?.status === 404) { | ||
return { | ||
message: "Invalid API URL, please adjust API URL", | ||
status: response?.status, | ||
}; | ||
} else { | ||
return { | ||
message: "something went wrong with request", | ||
status: response?.status, | ||
}; | ||
} | ||
}; | ||
export const errorHandler = (error) => { | ||
|
||
const LABELS_URL = "/loki/api/v1/labels"; | ||
const QUERY_URL = "/loki/api/v1/query_range"; | ||
|
||
const { request, response } = error; | ||
const url = error?.response?.request?.responseURL | ||
|
||
|
||
let type = () => { | ||
switch(url) { | ||
case url?.includes(LABELS_URL): | ||
return 'labels'; | ||
case url?.includes(QUERY_URL): | ||
return 'query' | ||
default: return 'labels' | ||
} | ||
} | ||
|
||
if (response?.statusText) { | ||
const status = response?.status; | ||
|
||
return { | ||
message: "API " + response.statusText + ", Please adjust API URL", | ||
status, | ||
type: type() | ||
}; | ||
} else if (url && !url.includes(window.location.protocol)) { | ||
|
||
return { | ||
message: "Mixed Content Error, your View should be over same protocol as your API", | ||
status: 500, | ||
type : type() | ||
}; | ||
} else if (request) { | ||
if (error.stack.includes('Network Error')) { | ||
return { | ||
message: "Invalid API URL, please adjust API URL", | ||
status: 500, | ||
type: type() | ||
} | ||
} | ||
return { | ||
message: "server time out", | ||
status: response?.status, | ||
type: type() | ||
}; | ||
} else if (error?.stack?.includes("Invalid URL")) { | ||
return { | ||
message: "Invalid API URL, please adjust API URL", | ||
stauts: response?.status, | ||
type: type() | ||
}; | ||
} else if (error?.response?.status === 404) { | ||
return { | ||
message: "Invalid API URL, please adjust API URL", | ||
status: response?.status, | ||
type: type() | ||
}; | ||
} else { | ||
if (type === 'labels') return; | ||
|
||
return { | ||
message: "something went wrong with request", | ||
status: response?.status, | ||
type: type() | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
export * from "./setStartTime"; | ||
export * from "./setStopTime"; | ||
export * from "./setQueryLimit"; | ||
export * from "./setQueryStep"; | ||
export * from "./setRangeOpen"; | ||
export * from "./setTimeRangeLabel"; | ||
export * from "./setApiUrl"; | ||
export * from "./setQuery"; | ||
export * from "./setIsSubmit"; | ||
export * from "./setMatrixData"; | ||
export * from "./setQueryHistory"; | ||
export * from "./setHistoryOpen"; | ||
export * from "./setApiError"; | ||
export * from "./errorHandler"; | ||
export * from "./setLabels"; | ||
export * from "./createAlert"; | ||
export * from "./removeAlert"; | ||
export * from "./setFromTime"; | ||
export * from "./setToTime"; | ||
export * from "./setStartTime"; | ||
export * from "./setStopTime"; | ||
export * from "./setQueryLimit"; | ||
export * from "./setQueryStep"; | ||
export * from "./setRangeOpen"; | ||
export * from "./setTimeRangeLabel"; | ||
export * from "./setApiUrl"; | ||
export * from "./setQuery"; | ||
export * from "./setIsSubmit"; | ||
export * from "./setMatrixData"; | ||
export * from "./setQueryHistory"; | ||
export * from "./setHistoryOpen"; | ||
export * from "./setApiError"; | ||
export * from "./errorHandler"; | ||
export * from "./setLabels"; | ||
export * from "./createAlert"; | ||
export * from "./removeAlert"; | ||
export * from "./setFromTime"; | ||
export * from "./setToTime"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
import axios from "axios"; | ||
import { errorHandler } from "./errorHandler"; | ||
import { setApiError } from "./setApiError"; | ||
import { setLabels } from "./setLabels"; | ||
import setLabelValues from "./setLabelValues"; | ||
import setLoading from "./setLoading"; | ||
|
||
|
||
export default function loadLabelValues(label, labelList, apiUrl) { | ||
if (!label || (label?.length <= 0 && label.lsList.length <= 0)) { | ||
return () => {}; | ||
}; | ||
|
||
const url = apiUrl; | ||
|
||
const origin = window.location.origin | ||
|
||
const headers = { | ||
"Access-Control-Allow-Origin": origin, | ||
"Access-Control-Allow-Headers": ["Access-Control-Request-Headers", "Content-Type"], | ||
"Content-Type": "application/json", | ||
} | ||
|
||
const options = { | ||
method: "GET", | ||
headers: headers, | ||
mode: "cors", | ||
|
||
}; | ||
|
||
return async (dispatch) => { | ||
dispatch(setLoading(true)) | ||
|
||
await axios.get(`${url}/loki/api/v1/label/${label.name}/values`, options) | ||
?.then(response => { | ||
if (response?.data?.data) { | ||
const values = response?.data?.data?.map?.((value) => ({ | ||
name: value, | ||
selected: false, | ||
inverted: false | ||
})); | ||
|
||
const lsList = [...labelList]; | ||
lsList.forEach((l) => { | ||
if (l?.name === label?.name) { | ||
l.values = [...values]; | ||
} | ||
}); | ||
dispatch(setLabels(lsList)) | ||
} else if(!response) { | ||
dispatch(setApiError('URL NOT FOUND')) | ||
dispatch(setLabelValues([])) | ||
} | ||
|
||
dispatch(setLoading(false)); | ||
dispatch(setApiError('')) | ||
dispatch(setLabelValues(response?.data?.data)); | ||
|
||
}).catch(error => { | ||
dispatch(setLoading(false)) | ||
const { message } = errorHandler(url, error) | ||
dispatch(setApiError(message || 'API NOT FOUND')) | ||
dispatch(setLabelValues([])) | ||
console.err(error) | ||
}) | ||
} | ||
|
||
|
||
} | ||
import axios from "axios"; | ||
import { errorHandler } from "./errorHandler"; | ||
import { setApiError } from "./setApiError"; | ||
import { setLabels } from "./setLabels"; | ||
import setLabelValues from "./setLabelValues"; | ||
import setLoading from "./setLoading"; | ||
|
||
|
||
export default function loadLabelValues(label, labelList, apiUrl) { | ||
if (!label || (label?.length <= 0 && label.lsList.length <= 0)) { | ||
return () => {}; | ||
}; | ||
|
||
const url = apiUrl; | ||
|
||
const origin = window.location.origin | ||
|
||
const headers = { | ||
"Access-Control-Allow-Origin": origin, | ||
"Access-Control-Allow-Headers": ["Access-Control-Request-Headers", "Content-Type"], | ||
"Content-Type": "application/json", | ||
} | ||
|
||
const options = { | ||
method: "GET", | ||
headers: headers, | ||
mode: "cors", | ||
|
||
}; | ||
|
||
return async (dispatch) => { | ||
dispatch(setLoading(true)) | ||
|
||
await axios.get(`${url}/loki/api/v1/label/${label.name}/values`, options) | ||
?.then(response => { | ||
if (response?.data?.data) { | ||
const values = response?.data?.data?.map?.((value) => ({ | ||
name: value, | ||
selected: false, | ||
inverted: false | ||
})); | ||
|
||
const lsList = [...labelList]; | ||
lsList.forEach((l) => { | ||
if (l?.name === label?.name) { | ||
l.values = [...values]; | ||
} | ||
}); | ||
dispatch(setLabels(lsList)) | ||
} else if(!response) { | ||
dispatch(setApiError('URL NOT FOUND')) | ||
dispatch(setLabelValues([])) | ||
} | ||
|
||
dispatch(setLoading(false)); | ||
dispatch(setApiError('')) | ||
dispatch(setLabelValues(response?.data?.data)); | ||
|
||
}).catch(error => { | ||
dispatch(setLoading(false)) | ||
const { message } = errorHandler(url, error,'lavelValues') | ||
dispatch(setApiError(message || 'API NOT FOUND')) | ||
dispatch(setLabelValues([])) | ||
console.error(error) | ||
}) | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.