-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move error codes into another package
- Loading branch information
1 parent
58085d0
commit 92557b5
Showing
4 changed files
with
111 additions
and
90 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,50 +1,21 @@ | ||
package authenticator | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/snapp-incubator/soteria/pkg/acl" | ||
) | ||
import "github.com/snapp-incubator/soteria/internal/error" | ||
|
||
var ( | ||
ErrInvalidSigningMethod = errors.New("signing method does not match with authenticator signing method") | ||
ErrIssNotFound = errors.New("could not found iss in token claims") | ||
ErrSubNotFound = errors.New("could not found sub in token claims") | ||
ErrInvalidClaims = errors.New("invalid claims") | ||
ErrInvalidIP = errors.New("IP is not valid") | ||
ErrInvalidAccessType = errors.New("requested access type is invalid") | ||
ErrDecodeHashID = errors.New("could not decode hash id") | ||
ErrInvalidSecret = errors.New("invalid secret") | ||
ErrIncorrectPassword = errors.New("username or password is wrong") | ||
ErrInvalidSigningMethod = error.ErrInvalidSigningMethod | ||
ErrIssNotFound = error.ErrIssNotFound | ||
ErrSubNotFound = error.ErrSubNotFound | ||
ErrInvalidClaims = error.ErrInvalidClaims | ||
ErrInvalidIP = error.ErrInvalidIP | ||
ErrInvalidAccessType = error.ErrInvalidAccessType | ||
ErrDecodeHashID = error.ErrDecodeHashID | ||
ErrInvalidSecret = error.ErrInvalidSecret | ||
ErrIncorrectPassword = error.ErrIncorrectPassword | ||
) | ||
|
||
type TopicNotAllowedError struct { | ||
Issuer string | ||
Sub string | ||
AccessType acl.AccessType | ||
Topic string | ||
TopicType string | ||
} | ||
|
||
func (err TopicNotAllowedError) Error() string { | ||
return fmt.Sprintf("issuer %s with sub %s is not allowed to %s on topic %s (%s)", | ||
err.Issuer, err.Sub, err.AccessType, err.Topic, err.TopicType, | ||
) | ||
} | ||
|
||
type KeyNotFoundError struct { | ||
Issuer string | ||
} | ||
|
||
func (err KeyNotFoundError) Error() string { | ||
return fmt.Sprintf("cannot find issuer %s key", err.Issuer) | ||
} | ||
type TopicNotAllowedError = error.TopicNotAllowedError | ||
|
||
type InvalidTopicError struct { | ||
Topic string | ||
} | ||
type KeyNotFoundError = error.KeyNotFoundError | ||
|
||
func (err InvalidTopicError) Error() string { | ||
return fmt.Sprintf("provided topic %s is not valid", err.Topic) | ||
} | ||
type InvalidTopicError = error.InvalidTopicError |
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,50 @@ | ||
package error | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/snapp-incubator/soteria/pkg/acl" | ||
) | ||
|
||
var ( | ||
ErrInvalidSigningMethod = errors.New("signing method does not match with authenticator signing method") | ||
ErrIssNotFound = errors.New("could not found iss in token claims") | ||
ErrSubNotFound = errors.New("could not found sub in token claims") | ||
ErrInvalidClaims = errors.New("invalid claims") | ||
ErrInvalidIP = errors.New("IP is not valid") | ||
ErrInvalidAccessType = errors.New("requested access type is invalid") | ||
ErrDecodeHashID = errors.New("could not decode hash id") | ||
ErrInvalidSecret = errors.New("invalid secret") | ||
ErrIncorrectPassword = errors.New("username or password is wrong") | ||
) | ||
|
||
type TopicNotAllowedError struct { | ||
Issuer string | ||
Sub string | ||
AccessType acl.AccessType | ||
Topic string | ||
TopicType string | ||
} | ||
|
||
func (err TopicNotAllowedError) Error() string { | ||
return fmt.Sprintf("issuer %s with sub %s is not allowed to %s on topic %s (%s)", | ||
err.Issuer, err.Sub, err.AccessType, err.Topic, err.TopicType, | ||
) | ||
} | ||
|
||
type KeyNotFoundError struct { | ||
Issuer string | ||
} | ||
|
||
func (err KeyNotFoundError) Error() string { | ||
return fmt.Sprintf("cannot find issuer %s key", err.Issuer) | ||
} | ||
|
||
type InvalidTopicError struct { | ||
Topic string | ||
} | ||
|
||
func (err InvalidTopicError) Error() string { | ||
return fmt.Sprintf("provided topic %s is not valid", err.Topic) | ||
} |
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