Skip to content

Commit ec10b5b

Browse files
committed
fix: provide an explicit error for an invalid payload
also provide better tracing by setting the caused by error
1 parent 736d49b commit ec10b5b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

shard.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: jwt
2-
version: 1.3.0
2+
version: 1.3.1
33

44
authors:
55
- Potapov Sergey <blake131313@gmail.com>

src/jwt.cr

+6-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ module JWT
8080
end
8181

8282
{payload, header}
83-
rescue Base64::Error
84-
raise DecodeError.new("Invalid Base64")
85-
rescue JSON::ParseException
86-
raise DecodeError.new("Invalid JSON")
83+
rescue error : Base64::Error
84+
raise DecodeError.new("Invalid Base64", error)
85+
rescue error : JSON::ParseException
86+
raise DecodeError.new("Invalid JSON", error)
87+
rescue error : TypeCastError
88+
raise DecodeError.new("Invalid JWT payload", error)
8789
end
8890

8991
def encode_header(algorithm : Algorithm, **keys) : String

0 commit comments

Comments
 (0)