-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api-server): improve error handling and return status (#7937)
- never return 412 (it was never appropriate - create better error hierarchy to simplify handler - use in some places errors.Is Signed-off-by: Charly Molter <[email protected]>
- Loading branch information
Showing
21 changed files
with
101 additions
and
101 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
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 |
---|---|---|
@@ -1,17 +1,24 @@ | ||
package types | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"fmt" | ||
"reflect" | ||
) | ||
|
||
func NewMaxPageSizeExceeded(pageSize, limit int) error { | ||
return errors.Errorf("Invalid page size of %d. Maximum page size is %d", pageSize, limit) | ||
type InvalidPageSizeError struct { | ||
Reason string | ||
} | ||
|
||
func (a *InvalidPageSizeError) Error() string { | ||
return a.Reason | ||
} | ||
|
||
func IsMaxPageSizeExceeded(err error) bool { | ||
return strings.HasPrefix(err.Error(), "Invalid page size of") | ||
func (a *InvalidPageSizeError) Is(err error) bool { | ||
return reflect.TypeOf(a) == reflect.TypeOf(err) | ||
} | ||
|
||
func NewMaxPageSizeExceeded(pageSize, limit int) error { | ||
return &InvalidPageSizeError{Reason: fmt.Sprintf("invalid page size of %d. Maximum page size is %d", pageSize, limit)} | ||
} | ||
|
||
var InvalidPageSize = errors.New("Invalid page size") | ||
var InvalidPageSize = &InvalidPageSizeError{Reason: "invalid format"} |
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
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
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
Oops, something went wrong.