Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import cwms.cda.helpers.annotations.IgnoreRequiredQueryParamMismatch;
import io.javalin.apibuilder.CrudHandler;
import io.javalin.core.util.Header;
import io.javalin.http.BadRequestResponse;
import io.javalin.http.Context;
import io.javalin.http.HttpCode;
import io.javalin.http.HttpResponseException;
Expand All @@ -74,7 +75,9 @@
import java.nio.charset.StandardCharsets;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -283,7 +286,10 @@ public void getAll(@NotNull Context ctx) {
boolean includeAliases = ctx.queryParamAsClass(INCLUDE_ALIASES, Boolean.class)
.getOrDefault(false);
if (!unit.equalsIgnoreCase(UnitSystem.SI.getValue()) && !unit.equalsIgnoreCase(UnitSystem.EN.getValue())) {
throw new IllegalArgumentException(String.format("Provided unit system is not supported: %s", unit));
String errorMessage = String.format("Provided unit system is not supported: %s", unit);
Map<String, String> errorDetails = new HashMap<>();
errorDetails.put("message", errorMessage);
throw new BadRequestResponse(errorMessage, errorDetails);
}
String datum = ctx.queryParam(DATUM);
String begin = ctx.queryParam(BEGIN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,27 @@ void test_ts_backed_level_new_lrts_interval() throws Exception {
;
}

@Test
void test_ts_get_all_error() {
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSONV2)
.contentType(Formats.JSONV2)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(UNIT, "cfs")
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/levels/")
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_BAD_REQUEST))
.body("message", is("Bad Request"))
.body("source", is("User Input"))
.body("details.message", is("Provided unit system is not supported: cfs"))
;
}

@Test
void test_get_all_location_level() throws Exception {
Expand Down
Loading