Skip to content

Commit 4e49ffe

Browse files
committed
fix: no panic in middleware
1 parent 3e8c0ac commit 4e49ffe

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [unreleased]
99

1010
- Handle AWS Public URLs (ending with `.amazonaws.com`) separately while extracting TLDs for SameSite attribute.
11+
- Return `500` status instead of panic when `supertokens.Middleware` is used without initializing the SDK.
1112

1213
## [0.14.0] - 2023-09-11
1314

supertokens/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ func Init(config TypeInput) error {
3434
func Middleware(theirHandler http.Handler) http.Handler {
3535
instance, err := GetInstanceOrThrowError()
3636
if err != nil {
37-
panic("Please call supertokens.Init function before using the Middleware")
37+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
38+
http.Error(w, err.Error(), http.StatusInternalServerError)
39+
})
3840
}
3941
return instance.middleware(theirHandler)
4042
}

0 commit comments

Comments
 (0)