aboutsummaryrefslogtreecommitdiff
path: root/errors
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-09-03 15:00:03 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-09-03 15:00:03 +0530
commit95dfc551f7eaaf6e8ebdefce1b733951354ac40d (patch)
treeecabef39a94084c456eaf32bb508d8809d592c9f /errors
parentfc83df70b787e447bf31f4d99fa723c7e38544f2 (diff)
added JWT authorization middleware
Diffstat (limited to 'errors')
-rw-r--r--errors/errors.go5
-rw-r--r--errors/status.go8
2 files changed, 12 insertions, 1 deletions
diff --git a/errors/errors.go b/errors/errors.go
index 1cae027..16e1646 100644
--- a/errors/errors.go
+++ b/errors/errors.go
@@ -23,7 +23,7 @@ import (
var (
// 204
- ErrEmptyResponse = errors.New("No Records Found")
+ ErrEmptyResponse = errors.New("No Records Found")
// 400
ErrNoWhereCondition = errors.New("No Where Condition")
@@ -38,6 +38,9 @@ var (
// 401
ErrWrongPassword = errors.New("Wrong Password")
+ ErrInvalidAuthHeader = errors.New("Invalid Authorization Header")
+ ErrUnauthorized = errors.New("Unauthorized")
+ ErrSessionExpired = errors.New("Session Expired")
// 404
ErrNotFound = errors.New("Not Found")
diff --git a/errors/status.go b/errors/status.go
index b0da1ae..4767aeb 100644
--- a/errors/status.go
+++ b/errors/status.go
@@ -41,6 +41,14 @@ func StatusCodeFromErr(err error) int {
return http.StatusBadRequest
}
+ // 401
+ if errors.Is(err, ErrWrongPassword) ||
+ errors.Is(err, ErrUnauthorized) ||
+ errors.Is(err, ErrInvalidAuthHeader) ||
+ errors.Is(err, ErrSessionExpired) {
+ return http.StatusUnauthorized
+ }
+
// 404
if errors.Is(err, ErrNotFound) ||
errors.Is(err, ErrBrandNotFound) {