001package io.avaje.http.api; 002 003import java.util.Map; 004 005/** 006 * Exception used with Validator. 007 * <p> 008 * Typically this is used when validating a bean populated by request 009 * body content. 010 * <p> 011 * Generally this exception type is registered with an exception handler 012 * and configured to return a 422 or 400 http status response with the 013 * errors as a map of fields to error message. 014 */ 015public class ValidationException extends IllegalArgumentException { 016 017 private int status = 422; 018 019 private Map<String, Object> errors; 020 021 /** 022 * Create with a message. 023 */ 024 public ValidationException(String message) { 025 super(message); 026 } 027 028 /** 029 * Create with a status and message. 030 */ 031 public ValidationException(int status, String message) { 032 super(message); 033 this.status = status; 034 } 035 036 /** 037 * Create with a status message and errors. 038 */ 039 public ValidationException(int status, String message, Map<String, Object> errors) { 040 super(message); 041 this.status = status; 042 this.errors = errors; 043 } 044 045 /** 046 * Return the suggested HTTP status to use in the response. 047 */ 048 public int getStatus() { 049 return status; 050 } 051 052 /** 053 * Set the suggested HTTP status to use in the response. 054 */ 055 public void setStatus(int status) { 056 this.status = status; 057 } 058 059 /** 060 * Return the errors typically as a map of field to error message. 061 */ 062 public Map<String, Object> getErrors() { 063 return errors; 064 } 065 066 /** 067 * Set the errors. 068 */ 069 public void setErrors(Map<String, Object> errors) { 070 this.errors = errors; 071 } 072}