forked from TrueCloudLab/frostfs-sdk-go
[#274] client/status: Support INVALID_ARGUMENT status
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
b9092aeb0c
commit
d00892f418
5 changed files with 128 additions and 6 deletions
|
@ -238,3 +238,61 @@ func (x *NodeUnderMaintenance) SetMessage(v string) {
|
|||
func (x NodeUnderMaintenance) Message() string {
|
||||
return x.v2.Message()
|
||||
}
|
||||
|
||||
// InvalidArgument describes failure status related to invalid argument.
|
||||
// Instances provide Status and StatusV2 interfaces.
|
||||
type InvalidArgument struct {
|
||||
v2 status.Status
|
||||
}
|
||||
|
||||
const defaultInvalidArgumentMsg = "argument is invalid"
|
||||
|
||||
// Error implements the error interface.
|
||||
func (x *InvalidArgument) Error() string {
|
||||
msg := x.v2.Message()
|
||||
if msg == "" {
|
||||
msg = defaultInvalidArgumentMsg
|
||||
}
|
||||
|
||||
return errMessageStatusV2(
|
||||
globalizeCodeV2(status.InvalidArgument, status.GlobalizeCommonFail),
|
||||
msg,
|
||||
)
|
||||
}
|
||||
|
||||
// implements local interface defined in FromStatusV2 func.
|
||||
func (x *InvalidArgument) fromStatusV2(st *status.Status) {
|
||||
x.v2 = *st
|
||||
}
|
||||
|
||||
// ToStatusV2 implements StatusV2 interface method.
|
||||
// If the value was returned by FromStatusV2, returns the source message.
|
||||
// Otherwise, returns message with
|
||||
// - code: INVALID_ARGUMENT;
|
||||
// - string message: written message via SetMessage or
|
||||
// "argument is invalid" as a default message;
|
||||
// - details: empty.
|
||||
func (x InvalidArgument) ToStatusV2() *status.Status {
|
||||
x.v2.SetCode(globalizeCodeV2(status.InvalidArgument, status.GlobalizeCommonFail))
|
||||
if x.v2.Message() == "" {
|
||||
x.v2.SetMessage(defaultInvalidArgumentMsg)
|
||||
}
|
||||
|
||||
return &x.v2
|
||||
}
|
||||
|
||||
// SetMessage writes invalid argument failure message.
|
||||
// Message should be used for debug purposes only.
|
||||
//
|
||||
// See also Message.
|
||||
func (x *InvalidArgument) SetMessage(v string) {
|
||||
x.v2.SetMessage(v)
|
||||
}
|
||||
|
||||
// Message returns status message. Zero status returns empty message.
|
||||
// Message should be used for debug purposes only.
|
||||
//
|
||||
// See also SetMessage.
|
||||
func (x InvalidArgument) Message() string {
|
||||
return x.v2.Message()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue