Skip to content

Commit

Permalink
change error messages to print stack
Browse files Browse the repository at this point in the history
  • Loading branch information
holashchand committed Sep 12, 2023
1 parent 78c9c8b commit 03145c7
Show file tree
Hide file tree
Showing 35 changed files with 137 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package in.divoc.api.authenticator;


import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -45,7 +46,7 @@ public void notify(String to, String otp) throws IOException {
System.out.println(response.toString());
}
} catch (IOException e) {
logger.error("Exception occurred while notifying: {}", e.getMessage());
logger.error("Exception occurred while notifying: {}", ExceptionUtils.getStackTrace(e));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import dev.sunbirdrc.claim.entity.Claim;
import dev.sunbirdrc.registry.middleware.service.ConditionResolverService;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -35,7 +36,7 @@ public boolean isAuthorizedAttestor(Claim claim, JsonNode attestorNode) {
);
return conditionResolverService.evaluate(resolvedCondition);
} catch (Exception e) {
logger.error("Exception occurred while resolving condition {}", e.getMessage());
logger.error("Exception occurred while resolving condition {}", ExceptionUtils.getStackTrace(e));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.commons.collections4.KeyValue;
import org.apache.commons.collections4.keyvalue.DefaultKeyValue;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
Expand Down Expand Up @@ -200,7 +201,7 @@ public RestStatus addEntity(String index, String entityId, JsonNode inputEntity)
Map<String, Object> inputMap = JSONUtil.convertJsonNodeToMap(inputEntity);
response = getClient(index).index(new IndexRequest(index, searchType, entityId).source(inputMap), RequestOptions.DEFAULT);
} catch (IOException e) {
logger.error("Exception in adding record to ElasticSearch: {}", e.getMessage());
logger.error("Exception in adding record to ElasticSearch: {}", ExceptionUtils.getStackTrace(e));
}
return response.status();
}
Expand Down Expand Up @@ -242,7 +243,7 @@ public RestStatus updateEntity(String index, String osid, JsonNode inputEntity)
logger.debug("updateEntity inputEntity {}", inputEntity);
response = getClient(index.toLowerCase()).update(new UpdateRequest(index.toLowerCase(), searchType, osid).doc(inputMap), RequestOptions.DEFAULT);
} catch (IOException e) {
logger.error("Exception in updating a record to ElasticSearch: {}", e.getMessage());
logger.error("Exception in updating a record to ElasticSearch: {}", ExceptionUtils.getStackTrace(e));
}
return response.status();
}
Expand All @@ -264,7 +265,7 @@ public RestStatus deleteEntity(String index, String osid) {
readMap.put(Constants.STATUS_KEYWORD, Constants.STATUS_INACTIVE);
response = getClient(indexL).update(new UpdateRequest(indexL, searchType, osid).doc(readMap), RequestOptions.DEFAULT);
} catch (NullPointerException | IOException e) {
logger.error("exception in deleteEntity {}", e.getMessage());
logger.error("exception in deleteEntity {}", ExceptionUtils.getStackTrace(e));
return RestStatus.NOT_FOUND;
}
return response.status();
Expand Down Expand Up @@ -308,7 +309,7 @@ public ComponentHealthInfo getHealthInfo() {
ClusterHealthResponse health = getClient("schema").cluster().health(request, RequestOptions.DEFAULT);
return new ComponentHealthInfo(getServiceName(), Arrays.asList("yellow", "green").contains(health.getStatus().name().toLowerCase()), "", "");
} catch (IOException e) {
logger.error("Elastic health status {}", e.getMessage());
logger.error("Elastic health status {}", ExceptionUtils.getStackTrace(e));
return new ComponentHealthInfo(getServiceName(), false, CONNECTION_FAILURE, e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.NestedExceptionUtils;

public class JSONUtil {

Expand Down Expand Up @@ -298,7 +300,7 @@ public static JsonNode removeNodesByPath(JsonNode root, Set<String> nodePaths) t
try {
doc.delete(jsonPath);
} catch (Exception e) {
logger.error("Path not found {} {}", jsonPath, e.getMessage());
logger.error("Path not found {} {}", jsonPath, ExceptionUtils.getStackTrace(e));
}
}
return convertStringJsonNode(doc.jsonString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.sunbirdrc.plugin.services;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -69,8 +70,8 @@ public String fetchClientToken() {
ResponseEntity<Map> response = null;
try {
response = restTemplateProvider.exchange(divocKeycloakUrl, HttpMethod.POST, entity, Map.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Fetching divoc token failed: {}", exception.getMessage());
} catch (HttpClientErrorException | HttpServerErrorException e) {
LOGGER.error("Fetching divoc token failed: {}", ExceptionUtils.getStackTrace(e));
}
if (response != null && response.getBody() != null && response.getBody().containsKey(ACCESS_TOKEN)) {
LOGGER.info("Divoc token fetch successfully.");
Expand All @@ -92,8 +93,8 @@ public byte[] fetchDivocPdf(String clientToken, String preEnrollmentCode, String
try {
response = restTemplateProvider.exchange(divocUrl, HttpMethod.POST, entity, byte[].class);
return response.getBody();
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Fetching divoc PDF failed: {}", exception.getMessage());
} catch (HttpClientErrorException | HttpServerErrorException e) {
LOGGER.error("Fetching divoc PDF failed: {}", ExceptionUtils.getStackTrace(e));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.sunbirdrc.pojos.PluginFile;
import dev.sunbirdrc.pojos.PluginResponseMessage;
import dev.sunbirdrc.pojos.attestation.Action;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -69,7 +70,7 @@ public ResponseEntity callbackHandler(@RequestHeader Map<String, String> headers
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(queryParams.get(Constants.HUB_CHALLENGE));
}
} catch (Exception e) {
LOGGER.error("Failed fetching mosip pdf: {}", e.getMessage());
LOGGER.error("Failed fetching mosip pdf: {}", ExceptionUtils.getStackTrace(e));
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(queryParams.get(Constants.HUB_CHALLENGE));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.sunbirdrc.plugin.dto.AuthRequestDto;
import dev.sunbirdrc.plugin.dto.RequestCredentialsDto;
import dev.sunbirdrc.plugin.dto.RequestDto;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -51,8 +52,8 @@ public HttpHeaders getAuthTokenHeader() {
ResponseEntity<String> response = null;
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.AUTH_URL, HttpMethod.POST, entity, String.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Get auth token failed: {}", exception.getMessage());
} catch (HttpClientErrorException | HttpServerErrorException e) {
LOGGER.error("Get auth token failed: {}", ExceptionUtils.getStackTrace(e));
}
if (response != null && response.getStatusCode() == HttpStatus.OK) {
LOGGER.info("Successfully authenticated with mosip");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import dev.sunbirdrc.plugin.constant.Constants;
import dev.sunbirdrc.plugin.dto.*;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -79,8 +80,8 @@ void subscribeForPrintServiceEvents() {
ResponseEntity<String> response = null;
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.SUBSCRIBE_URL, HttpMethod.POST, entity, String.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Subscription to topic failed: {}", exception.getMessage());
} catch (HttpClientErrorException | HttpServerErrorException e) {
LOGGER.error("Subscription to topic failed: {}", ExceptionUtils.getStackTrace(e));
}
if (response != null && response.getStatusCode() == HttpStatus.ACCEPTED) {
LOGGER.info("subscribed for topic {} at hub", topic);
Expand All @@ -102,8 +103,8 @@ private void registerTopic() {
ResponseEntity<String> response = null;
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.REGISTER_URL, HttpMethod.POST, entity, String.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Register topic failed: {}", exception.getMessage());
} catch (HttpClientErrorException | HttpServerErrorException e) {
LOGGER.error("Register topic failed: {}", ExceptionUtils.getStackTrace(e));
}
if (response != null && response.getStatusCode() == HttpStatus.ACCEPTED) {
LOGGER.info("topic {} registered at hub", topic);
Expand All @@ -129,8 +130,8 @@ public Object generateOTP(SendOTPDto otpDto) {
ResponseEntity<Object> response = null;
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.OTP_URL, HttpMethod.POST, entity, Object.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Generate otp failed failed: {}", exception.getMessage());
} catch (HttpClientErrorException | HttpServerErrorException e) {
LOGGER.error("Generate otp failed failed: {}", ExceptionUtils.getStackTrace(e));
}
if (response != null && response.getStatusCode() == HttpStatus.OK) {
LOGGER.info("Successfully generated otp");
Expand Down Expand Up @@ -172,8 +173,8 @@ public Object fetchCredentials(FetchCredentialsDto fetchCredentialsDto) {
ResponseEntity<Object> response = null;
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.CREDENTIALS_URL, HttpMethod.POST, entity, Object.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Generate credentials failed failed: {}", exception.getMessage());
} catch (HttpClientErrorException | HttpServerErrorException e) {
LOGGER.error("Generate credentials failed failed: {}", ExceptionUtils.getStackTrace(e));
}
if (response != null && response.getStatusCode() == HttpStatus.OK) {
LOGGER.info("Successfully generated credentials");
Expand All @@ -195,8 +196,8 @@ public byte[] fetchMosipPdf(Map<String, String> requestHeaders, String requestBo
try {
response = restTemplateProvider.exchange(printUrl + Constants.PRINT_PDF_URL, HttpMethod.POST, entity, byte[].class);
return response.getBody();
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Failed fetching pdf failed: {}", exception.getMessage());
} catch (HttpClientErrorException | HttpServerErrorException e) {
LOGGER.error("Failed fetching pdf failed: {}", ExceptionUtils.getStackTrace(e));
}
LOGGER.error("Failed fetching pdf failed: ");
return null;
Expand Down
5 changes: 3 additions & 2 deletions java/pojos/src/main/java/dev/sunbirdrc/pojos/APIMessage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.sunbirdrc.pojos;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -41,8 +42,8 @@ public APIMessage(HttpServletRequest servletRequest) {
if(body != null && !body.isEmpty()) {
try {
request = new ObjectMapper().readValue(body, Request.class);
} catch (IOException jpe) {
logger.error("Can't read request body: {}", jpe.getMessage());
} catch (IOException e) {
logger.error("Can't read request body: {}", ExceptionUtils.getStackTrace(e));
request = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.sunbirdrc.pojos;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.util.ContentCachingResponseWrapper;
Expand Down Expand Up @@ -41,14 +42,14 @@ public void writeResponseBody(String content) {
bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
bufferedWriter.write(content);
}
} catch (Exception ex) {
logger.error("ERROR IN SENDING RESPONSE: {}", ex.getMessage());
} catch (Exception e) {
logger.error("ERROR IN SENDING RESPONSE: {}", ExceptionUtils.getStackTrace(e));
} finally {
if (bufferedWriter != null) {
try {
bufferedWriter.close();
} catch (Exception ex) {
logger.error("ERROR in closing stream: {}", ex.getMessage());
} catch (Exception e) {
logger.error("ERROR in closing stream: {}", ExceptionUtils.getStackTrace(e));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -38,7 +39,7 @@ public MinioClient minioClient() {
logger.info("Minio bucket already exists: {}", bucketName);
}
} catch (Exception e) {
logger.error("Minio initialization failed: {}", e.getMessage());
logger.error("Minio initialization failed: {}", ExceptionUtils.getStackTrace(e));
}
return minioClient;
}
Expand Down
Loading

0 comments on commit 03145c7

Please sign in to comment.