Updated code fix.
This commit is contained in:
@@ -208,7 +208,6 @@ public class AppointmentDao {
|
|||||||
}
|
}
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.ERROR_IN_GENERATING_NDG_TRY_AGAIN));
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.ERROR_IN_GENERATING_NDG_TRY_AGAIN));
|
||||||
} catch (FeignException.Forbidden forbiddenException) {
|
} catch (FeignException.Forbidden forbiddenException) {
|
||||||
attempt++;
|
|
||||||
log.error("Failed to login to odessa due to some error");
|
log.error("Failed to login to odessa due to some error");
|
||||||
|
|
||||||
// Extract raw response body
|
// Extract raw response body
|
||||||
@@ -245,14 +244,16 @@ public class AppointmentDao {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error parsing JSON response: {}", e.getMessage());
|
log.error("Error parsing JSON response: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
if (attempt >= maxRetries) {
|
if (attempt + 1 < maxRetries) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale("Maximum retry attempts reached while trying to login to Odessa."));
|
regenerateTokenAndSave(hub);
|
||||||
} else {
|
} else {
|
||||||
loginToOdessa(hub, application);
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale("Maximum retry attempts reached while trying to login to Odessa."));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to authenticate user on Odessa : {}", e.getMessage(), e);
|
log.error("Failed to authenticate user on Odessa : {}", e.getMessage(), e);
|
||||||
throw new RuntimeException("Authentication failed on Odessa. try again", e);
|
throw new RuntimeException("Authentication failed on Odessa. try again", e);
|
||||||
|
} finally {
|
||||||
|
attempt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -430,6 +431,7 @@ public class AppointmentDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private HubEntity authenticateAndSaveToken(HubEntity hub) {
|
private HubEntity authenticateAndSaveToken(HubEntity hub) {
|
||||||
|
|
||||||
int maxRetries = 3;
|
int maxRetries = 3;
|
||||||
int attempt = 0;
|
int attempt = 0;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
@@ -467,7 +469,6 @@ public class AppointmentDao {
|
|||||||
// Handle non-OK response
|
// Handle non-OK response
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.ERROR_IN_GENERATING_NDG_TRY_AGAIN));
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.ERROR_IN_GENERATING_NDG_TRY_AGAIN));
|
||||||
} catch (FeignException.Forbidden forbiddenException) {
|
} catch (FeignException.Forbidden forbiddenException) {
|
||||||
attempt++;
|
|
||||||
log.error("Failed to login to odessa due to some error occurred.");
|
log.error("Failed to login to odessa due to some error occurred.");
|
||||||
|
|
||||||
// Extract raw response body
|
// Extract raw response body
|
||||||
@@ -500,14 +501,16 @@ public class AppointmentDao {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error parsing JSON response: {}", e.getMessage());
|
log.error("Error parsing JSON response: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
if (attempt >= maxRetries) {
|
if (attempt + 1 < maxRetries) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale("Maximum retry attempts reached while trying to login to Odessa."));
|
|
||||||
} else {
|
|
||||||
regenerateTokenAndSave(hub);
|
regenerateTokenAndSave(hub);
|
||||||
|
} else {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale("Maximum retry attempts reached while trying to login to Odessa."));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to authenticate user on Odessa : {}", e.getMessage(), e);
|
log.error("Failed to authenticate user on Odessa : {}", e.getMessage(), e);
|
||||||
throw new RuntimeException("Authentication failed on Odessa. try again", e);
|
throw new RuntimeException("Authentication failed on Odessa. try again", e);
|
||||||
|
} finally {
|
||||||
|
attempt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user