return early if not json

This commit is contained in:
dongfang committed 2025-02-12 03:05:58 +00:00
1 parent 4d12608a22
commit c3d92ec812
1 file changed
+7 -7
+7 -7
View File
@@ -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,7 +170,13 @@ 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');
if (!isJson) {
httpResponse.status = false;
httpResponse.message = "Response Not JSON";
return httpResponse;
}
try { try {
result = jmespath.search(result, jsonPath); result = jmespath.search(result, jsonPath);
} catch (error) { } catch (error) {
@@ -179,11 +184,6 @@ class NetworkService {
httpResponse.message = "JSONPath Search Error"; httpResponse.message = "JSONPath Search Error";
return httpResponse; return httpResponse;
} }
} else {
httpResponse.status = false;
httpResponse.message = "Response Not JSON";
return httpResponse;
}
} }
if (result === null || result === undefined) { if (result === null || result === undefined) {