Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public enum AdminServiceErrorCode {
INVALID_TIMESTAMP_EXCEPTION("KER-ADM-102", "Timestamp cannot be future date"),
LAST_UPDATED_PARSE_EXCEPTION("KER-ADM-103", "Error occurred while parsing lastUpdated timestamp"),
SYNC_JOB_DEF_FETCH_EXCEPTION("KER-ADM-104", "Error while fetching sync job def details"),
DATA_NOT_FOUND_EXCEPTION("KER-ADM-105", "data not found for sync job def");
DATA_NOT_FOUND_EXCEPTION("KER-ADM-105", "data not found for sync job def"),
VALIDATION_ERROR ("KER-ADM-106", "Validation error while fetching Certificate");

private final String errorCode;
private final String errorMessage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.mosip.kernel.syncdata.exception;

import java.util.List;

import io.mosip.kernel.core.exception.BaseUncheckedException;
import io.mosip.kernel.core.exception.ServiceError;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class SyncInvalidArgumentException extends BaseUncheckedException {

/**
Expand All @@ -20,6 +22,7 @@ public class SyncInvalidArgumentException extends BaseUncheckedException {
* @param list The error list.
*/
public SyncInvalidArgumentException(List<ServiceError> list) {
super(constructMessage(list));
this.list = list;
}

Expand All @@ -32,4 +35,11 @@ public List<ServiceError> getList() {
return list;
}

private static String constructMessage(List<ServiceError> list) {
return list.stream()
.map(ServiceError::getMessage)
.filter(Objects::nonNull)
.collect(Collectors.joining(", "));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.mosip.kernel.core.exception.ExceptionUtils;
import io.mosip.kernel.core.http.RequestWrapper;
import io.mosip.kernel.core.http.ResponseWrapper;
Expand Down Expand Up @@ -56,8 +55,7 @@ public KeyPairGenerateResponseDto getCertificate(String applicationId, Optional<
try {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(certificateUrl);
builder.queryParam("applicationId", applicationId);
if (referenceId.isPresent())
builder.queryParam("referenceId", referenceId.get());
referenceId.ifPresent(id -> builder.queryParam("referenceId", id));
ResponseEntity<String> responseEntity = restTemplate.getForEntity(builder.build().toUri(), String.class);

ResponseWrapper<KeyPairGenerateResponseDto> resp = objectMapper.readValue(responseEntity.getBody(),
Expand All @@ -67,6 +65,9 @@ public KeyPairGenerateResponseDto getCertificate(String applicationId, Optional<
throw new SyncInvalidArgumentException(resp.getErrors());

return resp.getResponse();
} catch (SyncInvalidArgumentException e) {
LOGGER.warn("Validation error while fetching Certificate: {}", e.getMessage());
throw new SyncDataServiceException(AdminServiceErrorCode.VALIDATION_ERROR.getErrorCode(), e.getMessage(), e);
} catch (Exception e) {
LOGGER.error("Failed to fetch Certificate from keymanager", e);
throw new SyncDataServiceException(AdminServiceErrorCode.INTERNAL_SERVER_ERROR.getErrorCode(),
Expand Down