From aa592cec8013edba9c4aeae77028acc2732dc02c Mon Sep 17 00:00:00 2001 From: Matt Bell <mappum@gmail.com> Date: Fri, 10 Oct 2014 13:59:40 -0700 Subject: [PATCH] commands: Added error marshalling to Response --- commands/response.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/commands/response.go b/commands/response.go index 85ce76fe..07e91d12 100644 --- a/commands/response.go +++ b/commands/response.go @@ -16,8 +16,8 @@ const ( // Error is a struct for marshalling errors type Error struct { - message string - code ErrorType + Message string + Code ErrorType } type EncodingType string @@ -50,6 +50,10 @@ func (r *Response) FormatError() Error { } func (r *Response) Marshal() ([]byte, error) { + if r.Error == nil && r.Value == nil { + return nil, fmt.Errorf("No error or value set, there is nothing to marshal") + } + enc := r.req.Option("enc") if enc == nil { return nil, fmt.Errorf("No encoding type was specified") @@ -61,5 +65,10 @@ func (r *Response) Marshal() ([]byte, error) { return nil, fmt.Errorf("No marshaller found for encoding type '%s'", enc) } - return marshaller(r.Value) + if r.Error != nil { + err := r.FormatError() + return marshaller(err) + } else { + return marshaller(r.Value) + } } -- GitLab