Search in sources :

Example 6 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class MinLengthRuler method verify.

@Override
public WebException verify(final String field, final Object value, final Rule rule) {
    WebException error = null;
    final int length = null == value ? Values.ZERO : value.toString().length();
    final int min = rule.getConfig().getInteger("min");
    if (length < min) {
        error = failure(field, value, rule);
    }
    return error;
}
Also used : WebException(io.vertx.up.exception.WebException)

Example 7 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class FileRigor method verify.

@Override
public WebException verify(final Map<String, List<Rule>> rulers, final Object body) {
    WebException error = null;
    if (!rulers.isEmpty()) {
        // Merge rulers here.
        final Set<Rule> rules = new HashSet<>();
        Observable.fromIterable(rulers.keySet()).map(rulers::get).flatMap(Observable::fromIterable).subscribe(rules::add);
        // Rules here.
        error = Ruler.verify(rules, "BODY", body);
    }
    return error;
}
Also used : WebException(io.vertx.up.exception.WebException) Rule(io.vertx.up.atom.Rule) HashSet(java.util.HashSet)

Example 8 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class Validator method replyError.

private <T> void replyError(final T proxy, final Method method, final ConstraintViolation<T> item) {
    if (null != item) {
        final WebException error = new _400ValidationException(this.getClass(), proxy.getClass(), method, item.getMessage());
        error.setReadible(item.getMessage());
        throw error;
    }
}
Also used : WebException(io.vertx.up.exception.WebException) io.vertx.up.exception._400ValidationException(io.vertx.up.exception._400ValidationException)

Example 9 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class AuthenticateEndurer method handle.

@Override
public void handle(final RoutingContext event) {
    if (event.failed()) {
        final Throwable ex = event.failure();
        if (ex instanceof WebException) {
            final WebException error = (WebException) ex;
            Answer.reply(event, Envelop.failure(error));
        } else {
            // Other exception found
            event.fail(ex);
        }
    } else {
        // Success, do not throw, continue to request
        event.next();
    }
}
Also used : WebException(io.vertx.up.exception.WebException)

Example 10 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class ServiceJet method reply405Error.

/**
 * Method not Allowed ( 405 )
 *
 * @param context
 */
private void reply405Error(final RoutingContext context) {
    final HttpServerRequest request = context.request();
    final WebException exception = new _405MethodForbiddenException(getClass(), request.method(), request.uri());
    Answer.reply(context, Envelop.failure(exception));
}
Also used : WebException(io.vertx.up.exception.WebException) io.vertx.up.exception._405MethodForbiddenException(io.vertx.up.exception._405MethodForbiddenException)

Aggregations

WebException (io.vertx.up.exception.WebException)17 JsonObject (io.vertx.core.json.JsonObject)2 Rule (io.vertx.up.atom.Rule)2 Envelop (io.vertx.up.atom.Envelop)1 Event (io.vertx.up.atom.agent.Event)1 io.vertx.up.exception._400ValidationException (io.vertx.up.exception._400ValidationException)1 io.vertx.up.exception._400ValidationRuleException (io.vertx.up.exception._400ValidationRuleException)1 io.vertx.up.exception._404ServiceNotFoundException (io.vertx.up.exception._404ServiceNotFoundException)1 io.vertx.up.exception._405MethodForbiddenException (io.vertx.up.exception._405MethodForbiddenException)1 io.vertx.up.exception._500EntityCastException (io.vertx.up.exception._500EntityCastException)1 io.vertx.up.exception._500InternalServerException (io.vertx.up.exception._500InternalServerException)1 Rigor (io.vertx.up.rs.announce.Rigor)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1