class CrSerializer::Exceptions::ValidationException

Overview

Exception thrown when an object is not valid and raise_on_invalid is true

Defined in:

CrSerializer/exceptions/validation_exception.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(validator : Validator) #

[View source]

Instance Method Detail

def to_json : String #

Returns a validation failed 400 JSON error for easy error handling with REST APIs

{
  "code":    400,
  "message": "Validation tests failed",
  "errors":  [
    "'password' should not be blank",
    "'age' should be greater than 1",
  ],
}

[View source]