Skip to content

Commit

Permalink
ok, this returns an actual HTTP 429 / TOO_MANY_REQUESTS. #9356
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Mar 20, 2024
1 parent 989eb94 commit 92e3650
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public enum DisplayMode {
DatasetVersionUI datasetVersionUI;
@Inject
PermissionsWrapper permissionsWrapper;
@Inject
NavigationWrapper navigationWrapper;
@Inject
FileDownloadHelper fileDownloadHelper;
@Inject
Expand Down Expand Up @@ -1936,7 +1938,7 @@ private void setIdByPersistentId() {
private String init(boolean initFull) {
// Check for rate limit exceeded. Must be done before anything else to prevent unnecessary processing.
if (!cacheFactory.checkRate(session.getUser(), new CheckRateLimitForDatasetPage(null,null))) {
return permissionsWrapper.notFound();
return navigationWrapper.tooManyRequests();
}
//System.out.println("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes
setDataverseSiteUrl(systemConfig.getDataverseSiteUrl());
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DataversePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public enum LinkMode {
@EJB
DataverseLinkingServiceBean linkingService;
@Inject PermissionsWrapper permissionsWrapper;
@Inject
NavigationWrapper navigationWrapper;
@Inject DataverseHeaderFragment dataverseHeaderFragment;
@EJB
PidProviderFactoryBean pidProviderFactoryBean;
Expand Down Expand Up @@ -325,7 +327,7 @@ public String init() {
//System.out.println("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes
// Check for rate limit exceeded. Must be done before anything else to prevent unnecessary processing.
if (!cacheFactory.checkRate(session.getUser(), new CheckRateLimitForCollectionPage(null,null))) {
return permissionsWrapper.notFound();
return navigationWrapper.tooManyRequests();
}
if (this.getAlias() != null || this.getId() != null || this.getOwnerId() == null) {// view mode for a dataverse
if (this.getAlias() != null) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/NavigationWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.logging.Logger;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.ViewScoped;
import jakarta.ws.rs.core.Response.Status;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -87,6 +88,10 @@ public String notAuthorized(){
}
}

public String tooManyRequests() {
return sendError(Status.TOO_MANY_REQUESTS.getStatusCode());
}

public String notFound() {
return sendError(HttpServletResponse.SC_NOT_FOUND);
}
Expand Down

0 comments on commit 92e3650

Please sign in to comment.