This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mohammadne
committed
Sep 12, 2021
1 parent
34acdb6
commit 51a7c17
Showing
6 changed files
with
130 additions
and
140 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package failures | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type jwtFailure struct { | ||
FailureMessage string `json:"message"` | ||
FailureStatus int `json:"status"` | ||
FailureCauses []string `json:"causes"` | ||
} | ||
|
||
// ==============================================================> methods | ||
|
||
func (f *jwtFailure) Message() string { | ||
return f.FailureMessage | ||
} | ||
|
||
func (f *jwtFailure) Status() int { | ||
return f.FailureStatus | ||
} | ||
|
||
func (f *jwtFailure) Causes() []string { | ||
return f.FailureCauses | ||
} | ||
|
||
func (f *jwtFailure) Error() string { | ||
return fmt.Sprintf( | ||
"message: %s - status: %d - causes: %v", | ||
f.FailureMessage, f.FailureStatus, f.FailureCauses, | ||
) | ||
} | ||
|
||
// ==============================================================> constructors | ||
|
||
type Jwt struct{} | ||
|
||
func (Jwt) New(message string, status int, causes []string) Failure { | ||
return &jwtFailure{ | ||
FailureMessage: message, | ||
FailureStatus: status, | ||
FailureCauses: causes, | ||
} | ||
} | ||
|
||
func (Jwt) NewUnprocessableToken(message string) Failure { | ||
return &jwtFailure{ | ||
FailureMessage: message, | ||
FailureStatus: http.StatusUnprocessableEntity, | ||
} | ||
} | ||
|
||
func (Jwt) NewInvalid(message string) Failure { | ||
return &jwtFailure{ | ||
FailureMessage: message, | ||
FailureStatus: http.StatusUnauthorized, | ||
} | ||
} | ||
|
||
func (Jwt) NewInternal(message string, errors ...error) Failure { | ||
causes := make([]string, 0, len(errors)) | ||
for index := 0; index < len(errors); index++ { | ||
causes = append(causes, errors[index].Error()) | ||
} | ||
|
||
return &jwtFailure{ | ||
FailureMessage: message, | ||
FailureStatus: http.StatusInternalServerError, | ||
FailureCauses: causes, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters