Skip to content
Snippets Groups Projects
Commit 67392718 authored by Chad Leong's avatar Chad Leong :speech_balloon:
Browse files

Merge branch 'handleRequestRejectedException' into 'master'

Change response code for RequestRejectedException

See merge request !453
parents 104edf76 a7e7afe6
No related branches found
No related tags found
1 merge request!453Change response code for RequestRejectedException
Pipeline #217838 failed
......@@ -7,10 +7,13 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.partition.middleware.GlobalExceptionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.web.firewall.HttpStatusRequestRejectedHandler;
import org.springframework.security.web.firewall.RequestRejectedHandler;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
......@@ -28,9 +31,13 @@ public class AzureExceptionMapper extends GlobalExceptionMapper {
@Autowired
private TelemetryClient telemetryClient;
@Bean
public RequestRejectedHandler requestRejectedHandler() {
return new HttpStatusRequestRejectedHandler();
}
@ExceptionHandler(HttpResponseException.class)
protected ResponseEntity<Object> handleHttpResponseException(HttpResponseException e) {
if (e.getResponse().getStatusCode() == HttpStatus.TOO_MANY_REQUESTS.value()) {
return this.getErrorResponse(new AppException(e.getResponse().getStatusCode(), e.getLocalizedMessage(), e.getMessage(), e));
}
......
......@@ -96,4 +96,10 @@ public abstract class BaseTestTemplate extends TestBase {
CloseableHttpResponse response = descriptor.run(getId(), "");
assertEquals(error(EntityUtils.toString(response.getEntity())), 401, response.getCode());
}
@Test
public void should_return400_when_makingHttpRequestWithoutValidUrl() throws Exception {
CloseableHttpResponse response = descriptor.run("/", testUtils.getAccessToken());
assertEquals(error(EntityUtils.toString(response.getEntity())), 400, response.getCode());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment