Merge branch 'feature/SUPPORT-9536_fix_mchd' into develop

This commit is contained in:
Eduard Tihomiorv 2025-11-07 10:03:49 +03:00
commit 8c33cbc7b8
4 changed files with 29 additions and 5 deletions

View file

@ -558,6 +558,9 @@ public class EmployeeInfoFileUploadService {
throw new LocalizedException("mchd_cant_parse", MESSAGE_SOURCE);
}
MchdInfoModel mchdInfoModel = mchdService.getMchdInfoModel(mchdGuid);
if (mchdInfoModel == null) {
throw new LocalizedException("mchd_esia_error", MESSAGE_SOURCE);
}
LocalDate now = LocalDate.now();
if (!mchdInfoModel.getStatus().equals("A")) {
throw new LocalizedException("mchd_status_invalid", MESSAGE_SOURCE);

View file

@ -6,6 +6,8 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
@ -37,19 +39,22 @@ public class MchdService {
}
try {
HttpResponse<String> response = executeRequest(accessToken, guid);
if (isEsiaMchdNotFoundError(response)) {
return null;
}
if (response.statusCode() != 200) {
if (isNewToken) {
throw new EsiaException(response.statusCode() + " " + response.body());
}
accessToken = esiaAuthService.getSystemAccessToken();
response = executeRequest(accessToken, guid);
if (isEsiaMchdNotFoundError(response)) {
return null;
}
if (response.statusCode() != 200) {
throw new EsiaException(response.statusCode() + " " + response.body());
}
}
return objectMapper.readValue(response.body(), MchdInfoModel.class);
}
catch (Exception e) {
@ -70,4 +75,18 @@ public class MchdService {
.build()
.send(getReq, HttpResponse.BodyHandlers.ofString());
}
private boolean isEsiaMchdNotFoundError(HttpResponse<String> response)
throws JsonProcessingException {
if (response.statusCode() == 400) {
JsonNode jsonNode = objectMapper.readTree(response.body())
.get("code");
if (jsonNode == null) {
return false;
}
String errorCode = jsonNode.asText();
return errorCode != null && errorCode.equals("ESIA-044009");
}
return false;
}
}

View file

@ -19,3 +19,4 @@ mchd_tree_expired=У одной из родительских доверенно
mchd_validate_principal=Некорректная машиночитаемая доверенность. Доверенность выдана не той организацией, под которой была осуществлена загрузка файлов.
av_file_infected=Файлы заражены вирусом
mchd_cant_parse=Некорректный формат машиночитаемой доверенности
mchd_esia_error=Некорректная машиночитаемая доверенность. Доверенность не найдена.

View file

@ -19,3 +19,4 @@ mchd_tree_expired=У одной из родительских доверенно
mchd_validate_principal=Некорректная машиночитаемая доверенность. Доверенность выдана не той организацией, под которой была осуществлена загрузка файлов.
av_file_infected=Файлы заражены вирусом
mchd_cant_parse=Некорректный формат машиночитаемой доверенности
mchd_esia_error=Некорректная машиночитаемая доверенность. Доверенность не найдена.