-
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.
- Loading branch information
Showing
28 changed files
with
361 additions
and
287 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package appError | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/morikuni/failure/v2" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
const ( | ||
ErrConfigError = "ConfigError" | ||
ErrDSLSyntaxError = "DSLSyntaxError" | ||
ErrDSLGenerationFailed = "DSLGenerationFailed" | ||
ErrStoreOperationFailed = "StoreOperationFailed" | ||
ErrRequestParameterInvalid = "RequestParameterInvalid" | ||
ErrServerError = "ServerError" | ||
ErrRequestForwardFailed = "RequestForwardError" | ||
ErrAuthenticationFailed = "AuthenticationFailed" | ||
) | ||
|
||
func ToGRPCError(err error) error { | ||
var code codes.Code | ||
switch failure.CodeOf(err) { | ||
case ErrConfigError: | ||
code = codes.InvalidArgument | ||
case ErrDSLSyntaxError: | ||
code = codes.InvalidArgument | ||
case ErrDSLGenerationFailed: | ||
code = codes.Internal | ||
case ErrStoreOperationFailed: | ||
code = codes.Internal | ||
case ErrRequestParameterInvalid: | ||
code = codes.InvalidArgument | ||
case ErrAuthenticationFailed: | ||
code = codes.Unauthenticated | ||
case ErrServerError: | ||
code = codes.Internal | ||
case ErrRequestForwardFailed: | ||
code = codes.Internal | ||
default: | ||
code = codes.Unknown | ||
} | ||
return status.Error(code, getGRPCErrorMessage(err)) | ||
} | ||
|
||
func getGRPCErrorMessage(err error) string { | ||
code := failure.CodeOf(err) | ||
message := failure.MessageOf(err) | ||
cause := failure.CauseOf(err) | ||
ret := fmt.Sprintf("code: %s, message: %s, cause: %s", code, message, cause) | ||
|
||
return ret | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.