forked from flyteorg/flyte
-
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.
Enforce max response metadata size (flyteorg#139)
- Loading branch information
Showing
7 changed files
with
57 additions
and
19 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
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,20 +1,25 @@ | ||
package util | ||
|
||
import ( | ||
"github.com/lyft/flyteadmin/pkg/common" | ||
"github.com/lyft/flyteadmin/pkg/errors" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
// Transforms errors to grpc-compatible error types. | ||
// Transforms errors to grpc-compatible error types and optionally truncates it if necessary. | ||
func TransformAndRecordError(err error, metrics *RequestMetrics) error { | ||
switch err := err.(type) { | ||
case errors.FlyteAdminError: | ||
metrics.Record(err.(errors.FlyteAdminError).Code()) | ||
return err | ||
default: | ||
metrics.Record(codes.Internal) | ||
return status.Error(codes.Internal, err.Error()) | ||
var errorMessage = err.Error() | ||
concatenateErrMessage := false | ||
if len(errorMessage) > common.MaxResponseStatusBytes { | ||
errorMessage = err.Error()[:common.MaxResponseStatusBytes] | ||
concatenateErrMessage = true | ||
} | ||
if flyteAdminError, ok := err.(errors.FlyteAdminError); !ok { | ||
err = errors.NewFlyteAdminError(codes.Internal, errorMessage) | ||
} else if concatenateErrMessage { | ||
err = errors.NewFlyteAdminError(flyteAdminError.Code(), errorMessage) | ||
} | ||
metrics.Record(err.(errors.FlyteAdminError).Code()) | ||
return err | ||
} |
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