Skip to content

Commit

Permalink
fixed error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
holashchand committed Sep 8, 2023
1 parent 2fc87d3 commit abf6d03
Show file tree
Hide file tree
Showing 27 changed files with 102 additions and 111 deletions.
1 change: 0 additions & 1 deletion java/.mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public static void main(String args[]) {
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -11,6 +13,7 @@
import static org.junit.Assert.*;

public class ConditionResolverServiceTest {
private static final Logger logger = LoggerFactory.getLogger(ConditionResolverServiceTest.class);
ConditionResolverService conditionResolverService = new ConditionResolverService();
@Test
public void shouldAbleToResolveRequesterPaths() throws IOException {
Expand Down Expand Up @@ -44,7 +47,7 @@ public void shouldReturnTrueForValidExpression() throws IOException {
try {
resolve = conditionResolverService.resolve(getStudentJsonNode(), requester, condition, attributes);
} catch (IOException e) {
e.printStackTrace();
logger.info("Exception occurred: {}", e.getMessage());
}
String attestor = "ATTESTOR";
resolve = conditionResolverService.resolve(getTeacherJsonNode(), attestor, resolve, attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import dev.sunbirdrc.pojos.AuditRecord;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.charset.StandardCharsets;
Expand All @@ -15,6 +17,7 @@
import static org.junit.Assert.*;

public class JSONUtilTest {
private static final Logger logger = LoggerFactory.getLogger(JSONUtilTest.class);
private static final String TEST_DIR = "src/test/resources/";
private static final String ACTUAL_DATA = "actual_data.json";
private static final String EXPECTED_DATA = "expected_data.json";
Expand Down Expand Up @@ -131,12 +134,8 @@ private String getContent(String fileName) {
}
return result.toString(StandardCharsets.UTF_8.name());

} catch (FileNotFoundException e1) {
e1.printStackTrace();

} catch (IOException e) {
e.printStackTrace();

logger.info("Exception occurred: {}", e.getMessage());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public String fetchClientToken() {
try {
response = restTemplateProvider.exchange(divocKeycloakUrl, HttpMethod.POST, entity, Map.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Fetching divoc token failed: ");
exception.printStackTrace();
LOGGER.error("Fetching divoc token failed: {}", exception.getMessage());
}
if (response != null && response.getBody() != null && response.getBody().containsKey(ACCESS_TOKEN)) {
LOGGER.info("Divoc token fetch successfully.");
Expand All @@ -94,8 +93,7 @@ public byte[] fetchDivocPdf(String clientToken, String preEnrollmentCode, String
response = restTemplateProvider.exchange(divocUrl, HttpMethod.POST, entity, byte[].class);
return response.getBody();
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Fetching divoc PDF failed: ", exception);
exception.printStackTrace();
LOGGER.error("Fetching divoc PDF failed: {}", exception.getMessage());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public HttpHeaders getAuthTokenHeader() {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.AUTH_URL, HttpMethod.POST, entity, String.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Get auth token failed: ");
exception.printStackTrace();
LOGGER.error("Get auth token failed: {}", exception.getMessage());
}
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 @@ -80,8 +80,7 @@ void subscribeForPrintServiceEvents() {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.SUBSCRIBE_URL, HttpMethod.POST, entity, String.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Subscription to topic failed: ");
exception.printStackTrace();
LOGGER.error("Subscription to topic failed: {}", exception.getMessage());
}
if (response != null && response.getStatusCode() == HttpStatus.ACCEPTED) {
LOGGER.info("subscribed for topic {} at hub", topic);
Expand All @@ -104,8 +103,7 @@ private void registerTopic() {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.REGISTER_URL, HttpMethod.POST, entity, String.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Register topic failed: ");
exception.printStackTrace();
LOGGER.error("Register topic failed: {}", exception.getMessage());
}
if (response != null && response.getStatusCode() == HttpStatus.ACCEPTED) {
LOGGER.info("topic {} registered at hub", topic);
Expand All @@ -132,8 +130,7 @@ public Object generateOTP(SendOTPDto otpDto) {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.OTP_URL, HttpMethod.POST, entity, Object.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Generate otp failed failed: ");
exception.printStackTrace();
LOGGER.error("Generate otp failed failed: {}", exception.getMessage());
}
if (response != null && response.getStatusCode() == HttpStatus.OK) {
LOGGER.info("Successfully generated otp");
Expand Down Expand Up @@ -176,8 +173,7 @@ public Object fetchCredentials(FetchCredentialsDto fetchCredentialsDto) {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.CREDENTIALS_URL, HttpMethod.POST, entity, Object.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Generate credentials failed failed: ");
exception.printStackTrace();
LOGGER.error("Generate credentials failed failed: {}", exception.getMessage());
}
if (response != null && response.getStatusCode() == HttpStatus.OK) {
LOGGER.info("Successfully generated credentials");
Expand All @@ -200,8 +196,7 @@ public byte[] fetchMosipPdf(Map<String, String> requestHeaders, String requestBo
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.printStackTrace();
LOGGER.error("Failed fetching pdf failed: {}", exception.getMessage());
}
LOGGER.error("Failed fetching pdf failed: ");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,8 @@ public void addInterceptors(InterceptorRegistry registry) {
if (validationEnabled) {
try {
registry.addInterceptor(validationInterceptor()).addPathPatterns("/add").order(orderIdx++);
} catch (IOException e) {
e.printStackTrace();
} catch (CustomException e) {
e.printStackTrace();
} catch (IOException | CustomException e) {
logger.info("Exception occurred while adding validation interceptor: {}", e.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void loadSchemasFromDB() {
}
logger.info("Loaded {} schema from DB", searchResults.get(Schema).size());
} catch (IOException e) {
e.printStackTrace();
logger.info("Exception occurred while loading schema from db: {}", e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public abstract class AbstractController {
public String uuidPropertyName;

ResponseEntity<Object> badRequestException(ResponseParams responseParams, Response response, String errorMessage) {
logger.info("Error in handling the invite {}", errorMessage);
logger.info("Error in handling the invite: {}", errorMessage);
responseParams.setStatus(Response.Status.UNSUCCESSFUL);
responseParams.setErrmsg(errorMessage);
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}

ResponseEntity<Object> internalErrorResponse(ResponseParams responseParams, Response response, Exception ex) {
logger.info("Error in handling the invite", ex);
logger.info("Error in handling the invite: {}", ex.getMessage());
responseParams.setStatus(Response.Status.UNSUCCESSFUL);
responseParams.setErrmsg("Error occurred");
if (!StringUtils.isEmpty(ex.getMessage())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import dev.sunbirdrc.registry.helper.RegistryHelper;
import dev.sunbirdrc.registry.model.dto.DocumentsResponse;
import dev.sunbirdrc.registry.service.FileStorageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -18,6 +20,7 @@
@Controller
@ConditionalOnProperty(name = "filestorage.enabled", havingValue = "true", matchIfMissing = true)
public class FileStorageController {
private static final Logger logger = LoggerFactory.getLogger(FileStorageController.class);
private final FileStorageService fileStorageService;
private final RegistryHelper registryHelper;

Expand All @@ -35,7 +38,7 @@ public ResponseEntity<DocumentsResponse> save(@RequestParam MultipartFile[] file
try {
registryHelper.authorize(entity, entityId, httpServletRequest);
} catch (Exception e) {
e.printStackTrace();
logger.info("Authorizing entity failed: {}", e.getMessage());
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
DocumentsResponse documentsResponse = fileStorageService.saveAndFetchFileNames(files, httpServletRequest.getRequestURI());
Expand All @@ -51,7 +54,7 @@ public ResponseEntity<DocumentsResponse> deleteMultipleFiles(@PathVariable Strin
try {
registryHelper.authorize(entity, entityId, httpServletRequest);
} catch (Exception e) {
e.printStackTrace();
logger.info("Authorizing entity failed: {}", e.getMessage());
return new ResponseEntity(HttpStatus.FORBIDDEN);
}
DocumentsResponse documentsResponse = fileStorageService.deleteFiles(files);
Expand All @@ -67,7 +70,7 @@ public ResponseEntity deleteAFile(@PathVariable String entity,
try {
registryHelper.authorize(entity, entityId, httpServletRequest);
} catch (Exception e) {
e.printStackTrace();
logger.info("Authorizing entity failed: {}", e.getMessage());
return new ResponseEntity(HttpStatus.FORBIDDEN);
}
return fileStorageService.deleteDocument(httpServletRequest.getRequestURI());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ResponseEntity createAttestationPolicy(@PathVariable String entityName, @
return badRequestException(responseParams, response, "Invalid entity name");
}
} catch (Exception e) {
logger.error("Failed persisting attestation policy: ", e);
logger.error("Failed persisting attestation policy: {}", e.getMessage());
return internalErrorResponse(responseParams, response, e);
}
}
Expand All @@ -70,7 +70,7 @@ public ResponseEntity getAttestationPolicies(@PathVariable String entityName, Ht
return badRequestException(responseParams, response, "Invalid entity name");
}
} catch (Exception e) {
logger.error("Failed getting attestation policy: ", e);
logger.error("Failed getting attestation policy: {}", e.getMessage());
return internalErrorResponse(responseParams, response, e);
}
}
Expand All @@ -93,7 +93,7 @@ public ResponseEntity updateAttestationPolicy(@PathVariable String entityName, @
}
return badRequestException(responseParams, response, "Invalid entity name");
} catch (Exception e) {
logger.error("Failed updating attestation policy: ", e);
logger.error("Failed updating attestation policy: {}", e.getMessage());
return internalErrorResponse(responseParams, response, e);
}
}
Expand All @@ -118,7 +118,7 @@ public ResponseEntity updateAttestationPolicyStatus(@PathVariable String entityN
}
return badRequestException(responseParams, response, "Invalid entity name");
} catch (Exception e) {
logger.error("Failed updating attestation policy: ", e);
logger.error("Failed updating attestation policy: {}", e.getMessage());
return internalErrorResponse(responseParams, response, e);
}
}
Expand All @@ -143,7 +143,7 @@ public ResponseEntity deleteAttestationPolicy(@PathVariable String entityName, @
}
return badRequestException(responseParams, response, "Invalid entity name");
} catch (Exception e) {
logger.error("Failed updating attestation policy: ", e);
logger.error("Failed updating attestation policy: {}", e.getMessage());
return internalErrorResponse(responseParams, response, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import dev.sunbirdrc.registry.entities.VerificationRequest;
import dev.sunbirdrc.registry.helper.RegistryHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -14,7 +16,7 @@

@Controller
public class RegistryCertificateController {

private static final Logger logger = LoggerFactory.getLogger(RegistryCertificateController.class);

private static final String VERIFIED = "verified";
private static final String RESULTS = "results";
Expand All @@ -41,6 +43,7 @@ public ResponseEntity<Object> verifyCertificate(@RequestBody VerificationRequest
return new ResponseEntity<>(response, HttpStatus.OK);
}
} catch (Exception e) {
logger.info("Exception occurred while verifying certificate: {}", e.getMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public ResponseEntity<Object> getAllClaims(@PathVariable String entityName, Page
return new ResponseEntity<>(claims, HttpStatus.OK);
} catch (Exception e) {
logger.error("Fetching claims failed {}", e.getMessage());
e.printStackTrace();
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Expand All @@ -68,10 +67,9 @@ public ResponseEntity<Object> getClaim(@PathVariable String entityName, @PathVar
return new ResponseEntity<>(claim, HttpStatus.OK);
} catch (HttpClientErrorException | HttpServerErrorException e) {
logger.error("Fetching claim failed {}", e.getMessage());
e.printStackTrace();
return new ResponseEntity<>(e.getStatusCode());
} catch (Exception exception) {
exception.printStackTrace();
logger.info("Exception occurred while fetching claim: {}", exception.getMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Expand Down Expand Up @@ -149,7 +147,6 @@ public ResponseEntity<Object> riseAttestation(HttpServletRequest request, @Reque
response.setResult(Collections.singletonMap("attestationOSID", attestationOSID));
} catch (Exception exception) {
logger.error("Exception occurred while saving attestation data {}", exception.getMessage());
exception.printStackTrace();
responseParams.setErrmsg(exception.getMessage());
response = new Response(Response.API_ID.SEND, HttpStatus.INTERNAL_SERVER_ERROR.toString(), responseParams);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
Expand Down
Loading

0 comments on commit abf6d03

Please sign in to comment.