mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-26 14:09:45 -08:00
Helpful error when query returns object or array
This commit is contained in:
parent
82352910bf
commit
e2e81091c3
|
@ -407,6 +407,9 @@ async function evaluateJsonQuery(data, jsonPath, jsonPathOperator, expectedValue
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
response = (jsonPath) ? await jsonata(jsonPath).evaluate(response) : response;
|
response = (jsonPath) ? await jsonata(jsonPath).evaluate(response) : response;
|
||||||
|
if (typeof response === "object" || Array.isArray(response) || response instanceof Date || typeof response === "function") {
|
||||||
|
throw new Error(`The post-JSON query evaluated response from the server is of type ${typeof response}, which cannot be directly compared to the expected value`);
|
||||||
|
}
|
||||||
let jsonQueryExpression;
|
let jsonQueryExpression;
|
||||||
switch (jsonPathOperator) {
|
switch (jsonPathOperator) {
|
||||||
case ">":
|
case ">":
|
||||||
|
|
|
@ -667,6 +667,10 @@ export async function evaluateJsonQuery(data: any, jsonPath: string, jsonPathOpe
|
||||||
// If a JSON path is provided, pre-evaluate the data using it.
|
// If a JSON path is provided, pre-evaluate the data using it.
|
||||||
response = (jsonPath) ? await jsonata(jsonPath).evaluate(response) : response;
|
response = (jsonPath) ? await jsonata(jsonPath).evaluate(response) : response;
|
||||||
|
|
||||||
|
if (typeof response === "object" || Array.isArray(response) || response instanceof Date || typeof response === "function") {
|
||||||
|
throw new Error(`The post-JSON query evaluated response from the server is of type ${typeof response}, which cannot be directly compared to the expected value`);
|
||||||
|
}
|
||||||
|
|
||||||
// Perform the comparison logic using the chosen operator
|
// Perform the comparison logic using the chosen operator
|
||||||
let jsonQueryExpression;
|
let jsonQueryExpression;
|
||||||
switch (jsonPathOperator) {
|
switch (jsonPathOperator) {
|
||||||
|
|
Loading…
Reference in a new issue