return early if not json
This commit is contained in:
1 parent
4d12608a22
commit
c3d92ec812
1 file changed
+10
-10
@@ -1,5 +1,4 @@
|
|||||||
import jmespath from 'jmespath';
|
import jmespath from 'jmespath';
|
||||||
import { errorMessages, successMessages } from "../utils/messages.js";
|
|
||||||
const SERVICE_NAME = "NetworkService";
|
const SERVICE_NAME = "NetworkService";
|
||||||
const UPROCK_ENDPOINT = "https://api.uprock.com/checkmate/push";
|
const UPROCK_ENDPOINT = "https://api.uprock.com/checkmate/push";
|
||||||
|
|
||||||
@@ -171,19 +170,20 @@ class NetworkService {
|
|||||||
if (jsonPath) {
|
if (jsonPath) {
|
||||||
const contentType = response.headers['content-type'];
|
const contentType = response.headers['content-type'];
|
||||||
|
|
||||||
if (contentType && contentType.includes('application/json')) {
|
const isJson = contentType?.includes('application/json');
|
||||||
try {
|
if (!isJson) {
|
||||||
result = jmespath.search(result, jsonPath);
|
|
||||||
} catch (error) {
|
|
||||||
httpResponse.status = false;
|
|
||||||
httpResponse.message = "JSONPath Search Error";
|
|
||||||
return httpResponse;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
httpResponse.status = false;
|
httpResponse.status = false;
|
||||||
httpResponse.message = "Response Not JSON";
|
httpResponse.message = "Response Not JSON";
|
||||||
return httpResponse;
|
return httpResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = jmespath.search(result, jsonPath);
|
||||||
|
} catch (error) {
|
||||||
|
httpResponse.status = false;
|
||||||
|
httpResponse.message = "JSONPath Search Error";
|
||||||
|
return httpResponse;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result === null || result === undefined) {
|
if (result === null || result === undefined) {
|
||||||
|
|||||||
Reference in new issue
Block a user