-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add grpc error handling to provide more descriptive errors; fix:…
… make CacheInfo public and modify a few methods; fix: remove import aliases; fix: make Close function return one error;
- Loading branch information
1 parent
113fdce
commit 9e2347e
Showing
7 changed files
with
86 additions
and
61 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
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,7 +1,32 @@ | ||
package errors | ||
package scserrors | ||
|
||
import "errors" | ||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func InvalidInputError(errMessage string) error { | ||
return errors.New("InvalidInputError: " + errMessage) | ||
} | ||
|
||
func InternalServerError(errMessage string) error { | ||
return errors.New("InternalServerError: " + errMessage) | ||
} | ||
|
||
func GrpcErrorConverter(grpcErr error) error { | ||
if grpcStatus, ok := status.FromError(grpcErr); ok { | ||
switch grpcStatus.Code().String() { | ||
case "AlreadyExists": | ||
return fmt.Errorf(fmt.Sprintf("%s: %s", grpcStatus.Code().String(), grpcStatus.Message())) | ||
case "InvalidArgument": | ||
return fmt.Errorf(fmt.Sprintf("%s: %s", grpcStatus.Code().String(), grpcStatus.Message())) | ||
case "NotFound": | ||
return fmt.Errorf(fmt.Sprintf("%s: %s", grpcStatus.Code().String(), grpcStatus.Message())) | ||
case "PermissionDenied": | ||
return fmt.Errorf(fmt.Sprintf("%s: %s", grpcStatus.Code().String(), grpcStatus.Message())) | ||
} | ||
} | ||
return InternalServerError("CacheService failed with an internal error'") | ||
} |
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