Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lucky/cookies/cookie_jar.cr
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class Lucky::CookieJar
raise Lucky::CookieOverflowError.new("size of '#{key}' cookie is too big")
end
cookies[key.to_s] = set_cookies[key.to_s] = raw_cookie
rescue IO::Error
raise InvalidCookieValueError.new(key)
rescue e : IO::Error
raise InvalidCookieValueError.new(key, cause: e)
end

private def encrypt(raw_value : String) : String
Expand Down
2 changes: 1 addition & 1 deletion src/lucky/cookies/flash_store.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Lucky::FlashStore
end
self
rescue e : JSON::ParseException
raise Lucky::InvalidFlashJSONError.new(session.get?(SESSION_KEY))
raise Lucky::InvalidFlashJSONError.new(session.get?(SESSION_KEY), cause: e)
end

def keep : Nil
Expand Down
14 changes: 8 additions & 6 deletions src/lucky/errors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module Lucky

getter request

def initialize(@request : HTTP::Request)
super "Failed to parse the request parameters."
def initialize(@request : HTTP::Request, cause = nil)
super "Failed to parse the request parameters.", cause
end

def renderable_status : Int32
Expand Down Expand Up @@ -126,10 +126,11 @@ module Lucky
class InvalidCookieValueError < Error
getter :key

def initialize(@key : String | Symbol)
def initialize(@key : String | Symbol, cause = nil)
super(_message, cause)
end

def message : String
private def _message
<<-ERROR
Cookie value for '#{key}' is invalid.

Expand Down Expand Up @@ -225,10 +226,11 @@ module Lucky
class InvalidFlashJSONError < Error
getter bad_json

def initialize(@bad_json : String?)
def initialize(@bad_json : String?, cause = nil)
super(_message, cause)
end

def message : String?
private def _message
<<-MESSAGE
The flash messages (stored as JSON) failed to parse in a JSON parser.
Here's what it tries to parse:
Expand Down
4 changes: 2 additions & 2 deletions src/lucky/json_body_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Lucky::JsonBodyParser
else
JSON.parse(body)
end
rescue JSON::ParseException
raise Lucky::ParamParsingError.new(@request)
rescue e : JSON::ParseException
raise Lucky::ParamParsingError.new(@request, cause: e)
end
end
4 changes: 2 additions & 2 deletions src/lucky/mime_type.cr
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ class Lucky::MimeType
# multiplied by 1000 and then handled as an integer.
begin
($1.to_f32 * 1000).round.to_u16
rescue ArgumentError | OverflowError
raise InvalidMediaRange.new("#{parameter} is not a valid qvalue")
rescue e : ArgumentError | OverflowError
raise InvalidMediaRange.new("#{parameter} is not a valid qvalue", cause: e)
end
else
1000u16
Expand Down
3 changes: 1 addition & 2 deletions src/lucky/support/message_encryptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module Lucky
private def set_cipher_key(cipher) : Nil
cipher.key = @secret
rescue error : ArgumentError
raise InvalidSecretKeyBase.new(<<-MESSAGE
raise InvalidSecretKeyBase.new <<-MESSAGE, cause: error
The secret key is invalid:

#{error.message}
Expand All @@ -78,7 +78,6 @@ module Lucky


MESSAGE
)
end

class InvalidSecretKeyBase < Exception
Expand Down
2 changes: 1 addition & 1 deletion src/lucky/support/message_verifier.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module Lucky
raise(InvalidSignatureError.new)
end
rescue e : Base64::Error | JSON::ParseException
raise(InvalidSignatureError.new)
raise InvalidSignatureError.new(cause: e)
end

def generate(value : String | Bytes) : String
Expand Down