Skip to content

Commit

Permalink
overwrite the IllegalArgumentException http code
Browse files Browse the repository at this point in the history
  • Loading branch information
lkonno committed Nov 21, 2023
1 parent c4f8511 commit d172ea1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
28 changes: 28 additions & 0 deletions src/main/java/io/cryostat/util/IllegalArgumentExceptionMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright The Cryostat Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cryostat.util;

import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;

@Provider
public class IllegalArgumentExceptionMapper implements ExceptionMapper<IllegalArgumentException> {
@Override
public Response toResponse(IllegalArgumentException exception) {
return Response.status(400).build();
}
}
12 changes: 2 additions & 10 deletions src/test/java/itest/RulesPostJsonIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;

@QuarkusIntegrationTest
@TestMethodOrder(OrderAnnotation.class)
Expand Down Expand Up @@ -107,12 +106,6 @@ void testAddRuleThrowsWhenMimeUnsupported() throws Exception {
ex.getCause().getMessage(), Matchers.equalTo("Unsupported Media Type"));
}

@DisabledIfEnvironmentVariable(
named = "CI",
matches = "true",
disabledReason =
"The server 500 seems to cause issues for the next test in the suite, ex. HTTP"
+ " connection closed when attempting to POST the next rule definition")
@Test
@Order(3)
void testAddRuleThrowsWhenMimeInvalid() throws Exception {
Expand All @@ -131,9 +124,8 @@ void testAddRuleThrowsWhenMimeInvalid() throws Exception {
Assertions.assertThrows(
ExecutionException.class, () -> response.get(10, TimeUnit.SECONDS));
MatcherAssert.assertThat(
((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(500));
MatcherAssert.assertThat(
ex.getCause().getMessage(), Matchers.equalTo("Internal Server Error"));
((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400));
MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request"));
}

@Test
Expand Down

0 comments on commit d172ea1

Please sign in to comment.