Skip to content

Commit

Permalink
[Parvathy, Rahul] | BAH-3703 | Fix. Improper Session Expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
parvathy00 committed Mar 21, 2024
1 parent 2a65f2d commit 68605d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.bahmni.openerp.web;

public class OdooSessionExpiredException extends RuntimeException {

public OdooSessionExpiredException() {
super("Odoo Session Expired");
}

public OdooSessionExpiredException(Throwable cause) {
super("Odoo Session Expired", cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public static void checkResponse(ResponseEntity<String> responseEntity) throws J
else if (jsonResponse.has("error")) {
JsonNode error = jsonResponse.get("error");
String errorMsg = error.get("message").asText();
int status = error.get("status").asInt();
int status = error.has("status") ? error.get("status").asInt() : error.get("code").asInt();
if (status == 100 || status == 403) throw new OdooSessionExpiredException();
throw new OdooRestException(String.format("Error found in response. Response status: %s. Error message: %s", status, errorMsg));
}
else{
else {
throw new OdooRestException(String.format("Response is empty"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.bahmni.openerp.web.OdooSessionExpiredException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.bahmni.openerp.web.OdooRestException;
Expand Down Expand Up @@ -72,6 +73,10 @@ public String post(String URL, String requestBody) {
logger.error("Post call to {} failed", URL, e);
logger.error("Post data: {}", requestBody);
throw new RuntimeException("Post call to " + URL + " failed", e);
} catch (OdooSessionExpiredException e) {
logger.warn("Session expired for user {}. Recreating user session.", username);
login();
return post(URL, requestBody);
}
}

Expand Down

0 comments on commit 68605d3

Please sign in to comment.