Skip to content

Commit

Permalink
fix: provide an explicit error for an invalid payload
Browse files Browse the repository at this point in the history
also provide better tracing by setting the caused by error
  • Loading branch information
stakach committed Dec 17, 2019
1 parent 736d49b commit ec10b5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: jwt
version: 1.3.0
version: 1.3.1

authors:
- Potapov Sergey <[email protected]>
Expand Down
10 changes: 6 additions & 4 deletions src/jwt.cr
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ module JWT
end

{payload, header}
rescue Base64::Error
raise DecodeError.new("Invalid Base64")
rescue JSON::ParseException
raise DecodeError.new("Invalid JSON")
rescue error : Base64::Error
raise DecodeError.new("Invalid Base64", error)
rescue error : JSON::ParseException
raise DecodeError.new("Invalid JSON", error)
rescue error : TypeCastError
raise DecodeError.new("Invalid JWT payload", error)
end

def encode_header(algorithm : Algorithm, **keys) : String
Expand Down

0 comments on commit ec10b5b

Please sign in to comment.