SUPPORT-8762

This commit is contained in:
kochetkov 2024-12-02 11:48:00 +03:00
parent 52306d2d22
commit e14353a565
3 changed files with 60 additions and 2 deletions

View file

@ -0,0 +1,8 @@
package ru.micord.ervu_eks.exception;
public class ConfigExecutorException extends RuntimeException{
public ConfigExecutorException(String message) {
super(message);
}
}

View file

@ -0,0 +1,27 @@
package ru.micord.ervu_eks.handler;
import org.springframework.stereotype.Component;
import ru.micord.ervu_eks.exception.ConfigExecutorException;
import ru.cg.webbpm.modules.core.error_handling.api.ProcessedWebException;
import ru.cg.webbpm.modules.core.error_handling.api.WebExceptionHandler;
@Component
public class ConfigExecutorExceptionHandler implements WebExceptionHandler {
@Override
public boolean accept(Throwable throwable) {
return throwable instanceof ConfigExecutorException;
}
@Override
public double weight() {
return 1000;
}
@Override
public ProcessedWebException process(Throwable throwable) {
return new ProcessedWebException()
.addMessage(throwable.getMessage());
}
}

View file

@ -6,8 +6,11 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import dto.ExportDataRequest;
import model.FileModel;
import org.slf4j.Logger;
@ -17,10 +20,13 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import ru.micord.ervu_eks.exception.ConfigExecutorException;
/**
* @author Evgenii Malkov
@ -43,8 +49,7 @@ public class ConfigExecutorService {
HttpHeaders headers = new HttpHeaders();
HttpEntity<ExportDataRequest> entity = new HttpEntity<>(request, headers);
ResponseEntity<byte[]> response = restTemplate.exchange(
url.concat("/").concat("downloadCSV"),
ResponseEntity<byte[]> response = restTemplate.exchange(url.concat("/").concat("downloadCSV"),
HttpMethod.POST, entity, byte[].class
);
@ -73,6 +78,24 @@ public class ConfigExecutorService {
);
return response.getBody();
}
catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.BAD_REQUEST) {
Map<String, String> responseMap = new Gson().fromJson(e.getResponseBodyAsString(),
new TypeToken<Map<String, String>>() {
}.getType()
);
String details = responseMap.get("details");
throw new ConfigExecutorException(details);
}
else {
throw new RuntimeException(
String.format("Failed call config executor service method: %s for ids: %s with error",
methodPath, ids
), e);
}
}
catch (Exception e) {
throw new RuntimeException(
String.format("Failed call config executor service method: %s for ids: %s with error",