return early if not json

This commit is contained in:
dongfang
2025-02-12 03:05:58 +00:00
parent 4d12608a22
commit c3d92ec812

View File

@@ -1,5 +1,4 @@
import jmespath from 'jmespath';
import { errorMessages, successMessages } from "../utils/messages.js";
const SERVICE_NAME = "NetworkService";
const UPROCK_ENDPOINT = "https://api.uprock.com/checkmate/push";
@@ -171,19 +170,20 @@ class NetworkService {
if (jsonPath) {
const contentType = response.headers['content-type'];
if (contentType && contentType.includes('application/json')) {
try {
result = jmespath.search(result, jsonPath);
} catch (error) {
httpResponse.status = false;
httpResponse.message = "JSONPath Search Error";
return httpResponse;
}
} else {
const isJson = contentType?.includes('application/json');
if (!isJson) {
httpResponse.status = false;
httpResponse.message = "Response Not JSON";
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) {