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

Instance methods inherited from class Object

to_json(io : IO, serialization_groups : Array(String), expand : Array(String))
to_json(serialization_groups : Array(String) = ["default"], expand : Array(String) = [] of String) : String
to_json
, to_pretty_json(indent : String = " ", serialization_groups : Array(String) = ["default"], expand : Array(String) = [] of String)
to_pretty_json(io : IO, serialization_groups : Array(String), expand : Array(String), indent : String = " ")
to_pretty_json
, to_yaml(serialization_groups : Array(String) = ["default"], expand : Array(String) = [] of String) : String to_yaml

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]
def to_s : String #

Returns failed valications as a string.

Validation tests failed:  `'password' should not be blank`, `'age' should be greater than 1`.

[View source]