Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
aa592cec
Commit
aa592cec
authored
10 years ago
by
Matt Bell
Committed by
Juan Batiz-Benet
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Added error marshalling to Response
parent
01938ac5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
3 deletions
+12
-3
commands/response.go
commands/response.go
+12
-3
No files found.
commands/response.go
View file @
aa592cec
...
@@ -16,8 +16,8 @@ const (
...
@@ -16,8 +16,8 @@ const (
// Error is a struct for marshalling errors
// Error is a struct for marshalling errors
type
Error
struct
{
type
Error
struct
{
m
essage
string
M
essage
string
c
ode
ErrorType
C
ode
ErrorType
}
}
type
EncodingType
string
type
EncodingType
string
...
@@ -50,6 +50,10 @@ func (r *Response) FormatError() Error {
...
@@ -50,6 +50,10 @@ func (r *Response) FormatError() Error {
}
}
func
(
r
*
Response
)
Marshal
()
([]
byte
,
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"
)
enc
:=
r
.
req
.
Option
(
"enc"
)
if
enc
==
nil
{
if
enc
==
nil
{
return
nil
,
fmt
.
Errorf
(
"No encoding type was specified"
)
return
nil
,
fmt
.
Errorf
(
"No encoding type was specified"
)
...
@@ -61,5 +65,10 @@ func (r *Response) Marshal() ([]byte, error) {
...
@@ -61,5 +65,10 @@ func (r *Response) Marshal() ([]byte, error) {
return
nil
,
fmt
.
Errorf
(
"No marshaller found for encoding type '%s'"
,
enc
)
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
)
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment