diff --git a/CHANGELOG.md b/CHANGELOG.md index bd033865..5197030e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] - Handle AWS Public URLs (ending with `.amazonaws.com`) separately while extracting TLDs for SameSite attribute. +- Return `500` status instead of panic when `supertokens.Middleware` is used without initializing the SDK. ## [0.14.0] - 2023-09-11 diff --git a/supertokens/main.go b/supertokens/main.go index c2e07ac9..338919b1 100644 --- a/supertokens/main.go +++ b/supertokens/main.go @@ -34,7 +34,9 @@ func Init(config TypeInput) error { func Middleware(theirHandler http.Handler) http.Handler { instance, err := GetInstanceOrThrowError() if err != nil { - panic("Please call supertokens.Init function before using the Middleware") + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + http.Error(w, err.Error(), http.StatusInternalServerError) + }) } return instance.middleware(theirHandler) }