Browse Source

use alias for http 422

tags/2.0.1
Jonathan Cobb 3 years ago
parent
commit
126e4b4da3
8 changed files with 9 additions and 9 deletions
  1. +1
    -1
      wizard-common/src/main/java/org/cobbzilla/wizard/client/ApiClientBase.java
  2. +1
    -1
      wizard-common/src/main/java/org/cobbzilla/wizard/client/script/ApiRunner.java
  3. +1
    -1
      wizard-common/src/main/java/org/cobbzilla/wizard/main/ScriptMainBase.java
  4. +1
    -1
      wizard-server-test/src/main/java/org/cobbzilla/wizardtest/resources/AbstractResourceIT.java
  5. +1
    -1
      wizard-server/src/main/java/org/cobbzilla/wizard/exceptionmappers/AbstractConstraintViolationExceptionMapper.java
  6. +1
    -1
      wizard-server/src/main/java/org/cobbzilla/wizard/exceptionmappers/MultiViolationExceptionMapper.java
  7. +1
    -1
      wizard-server/src/main/java/org/cobbzilla/wizard/exceptionmappers/SimpleViolationExceptionMapper.java
  8. +2
    -2
      wizard-server/src/main/java/org/cobbzilla/wizard/resources/ResourceUtil.java

+ 1
- 1
wizard-common/src/main/java/org/cobbzilla/wizard/client/ApiClientBase.java View File

@@ -200,7 +200,7 @@ public class ApiClientBase implements Cloneable, Closeable {
return new NotFoundException(request, response); return new NotFoundException(request, response);
case FORBIDDEN: case FORBIDDEN:
return new ForbiddenException(request, response); return new ForbiddenException(request, response);
case UNPROCESSABLE_ENTITY:
case INVALID:
return new ValidationException(request, response); return new ValidationException(request, response);
default: return new ApiException(request, response); default: return new ApiException(request, response);
} }


+ 1
- 1
wizard-common/src/main/java/org/cobbzilla/wizard/client/script/ApiRunner.java View File

@@ -304,7 +304,7 @@ public class ApiRunner {
responseEntity = empty(restResponse.json) || response.isRaw() ? null : json(restResponse.json, JsonNode.class); responseEntity = empty(restResponse.json) || response.isRaw() ? null : json(restResponse.json, JsonNode.class);
Object responseObject = responseEntity; Object responseObject = responseEntity;


if (response.getStatus() == HttpStatusCodes.UNPROCESSABLE_ENTITY) {
if (response.getStatus() == HttpStatusCodes.INVALID) {
if (responseEntity != null) { if (responseEntity != null) {
responseObject = new ValidationErrors( responseObject = new ValidationErrors(
Arrays.asList(fromJsonOrDie(responseEntity, ConstraintViolationBean[].class))); Arrays.asList(fromJsonOrDie(responseEntity, ConstraintViolationBean[].class)));


+ 1
- 1
wizard-common/src/main/java/org/cobbzilla/wizard/main/ScriptMainBase.java View File

@@ -352,7 +352,7 @@ public abstract class ScriptMainBase<OPT extends ScriptMainOptionsBase>
@Override public void unexpectedResponse(ApiScript script, RestResponse restResponse) { @Override public void unexpectedResponse(ApiScript script, RestResponse restResponse) {
final String msg; final String msg;
switch (restResponse.status) { switch (restResponse.status) {
case HttpStatusCodes.UNPROCESSABLE_ENTITY:
case HttpStatusCodes.INVALID:
msg = "Invalid: "+restResponse.json; msg = "Invalid: "+restResponse.json;
break; break;
case HttpStatusCodes.NOT_FOUND: case HttpStatusCodes.NOT_FOUND:


+ 1
- 1
wizard-server-test/src/main/java/org/cobbzilla/wizardtest/resources/AbstractResourceIT.java View File

@@ -355,7 +355,7 @@ public abstract class AbstractResourceIT<C extends PgRestServerConfiguration, S
} }


protected void assertExpectedViolations(RestResponse response, String... violationMessages) throws Exception{ protected void assertExpectedViolations(RestResponse response, String... violationMessages) throws Exception{
assertEquals(HttpStatusCodes.UNPROCESSABLE_ENTITY, response.status);
assertEquals(HttpStatusCodes.INVALID, response.status);
final ConstraintViolationBean[] violations = JsonUtil.FULL_MAPPER.readValue(response.json, ConstraintViolationBean[].class); final ConstraintViolationBean[] violations = JsonUtil.FULL_MAPPER.readValue(response.json, ConstraintViolationBean[].class);
assertExpectedViolations(violations, violationMessages); assertExpectedViolations(violations, violationMessages);
} }


+ 1
- 1
wizard-server/src/main/java/org/cobbzilla/wizard/exceptionmappers/AbstractConstraintViolationExceptionMapper.java View File

@@ -13,7 +13,7 @@ import static org.cobbzilla.wizard.resources.ResourceUtil.status;


public abstract class AbstractConstraintViolationExceptionMapper<E extends Exception> { public abstract class AbstractConstraintViolationExceptionMapper<E extends Exception> {


protected Response buildResponse(E e) { return status(HttpStatusCodes.UNPROCESSABLE_ENTITY, exception2json(e)); }
protected Response buildResponse(E e) { return status(HttpStatusCodes.INVALID, exception2json(e)); }


protected List<ConstraintViolationBean> exception2json(E e) { protected List<ConstraintViolationBean> exception2json(E e) {
return Collections.singletonList(mapGenericExceptionToConstraintViolationBean(e)); return Collections.singletonList(mapGenericExceptionToConstraintViolationBean(e));


+ 1
- 1
wizard-server/src/main/java/org/cobbzilla/wizard/exceptionmappers/MultiViolationExceptionMapper.java View File

@@ -13,7 +13,7 @@ import static org.cobbzilla.wizard.resources.ResourceUtil.status;
public class MultiViolationExceptionMapper implements ExceptionMapper<MultiViolationException> { public class MultiViolationExceptionMapper implements ExceptionMapper<MultiViolationException> {


@Override public Response toResponse(MultiViolationException e) { @Override public Response toResponse(MultiViolationException e) {
return status(HttpStatusCodes.UNPROCESSABLE_ENTITY, e.getViolations());
return status(HttpStatusCodes.INVALID, e.getViolations());
} }


} }

+ 1
- 1
wizard-server/src/main/java/org/cobbzilla/wizard/exceptionmappers/SimpleViolationExceptionMapper.java View File

@@ -17,7 +17,7 @@ public class SimpleViolationExceptionMapper implements ExceptionMapper<SimpleVio


@Override @Override
public Response toResponse(SimpleViolationException e) { public Response toResponse(SimpleViolationException e) {
return status(HttpStatusCodes.UNPROCESSABLE_ENTITY, getEntity(e));
return status(HttpStatusCodes.INVALID, getEntity(e));
} }


protected List<ConstraintViolationBean> getEntity(SimpleViolationException e) { protected List<ConstraintViolationBean> getEntity(SimpleViolationException e) {


+ 2
- 2
wizard-server/src/main/java/org/cobbzilla/wizard/resources/ResourceUtil.java View File

@@ -145,8 +145,8 @@ public class ResourceUtil {
public static Response unauthorized() { return status(UNAUTHORIZED); } public static Response unauthorized() { return status(UNAUTHORIZED); }
public static ResourceHttpException unauthorizedEx() { return new ResourceHttpException(UNAUTHORIZED); } public static ResourceHttpException unauthorizedEx() { return new ResourceHttpException(UNAUTHORIZED); }


public static Response invalid() { return status(UNPROCESSABLE_ENTITY); }
public static Response invalid(List<ConstraintViolationBean> violations) { return status(UNPROCESSABLE_ENTITY, violations); }
public static Response invalid() { return status(INVALID); }
public static Response invalid(List<ConstraintViolationBean> violations) { return status(INVALID, violations); }


public static Response invalid(ConstraintViolationBean violation) { public static Response invalid(ConstraintViolationBean violation) {
final List<ConstraintViolationBean> violations = new ArrayList<>(); final List<ConstraintViolationBean> violations = new ArrayList<>();


Loading…
Cancel
Save