-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from tmconsulting/fix-tests
1. Fix error creating based Aanda error messages
- Loading branch information
Showing
3 changed files
with
216 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,49 @@ | ||
package aandaSdk | ||
|
||
import "fmt" | ||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type AandaError struct { | ||
Status string `json:"status"` | ||
Code int `json:"code"` | ||
Type string `json:"type"` | ||
Note string `json:"note"` | ||
Status string `json:"status" json:"Status"` | ||
Code MustString `json:"code" json:"Code"` | ||
Type string `json:"type" json:"Type"` | ||
Note string `json:"note" json:"Note"` | ||
} | ||
|
||
func (o *AandaError) IsEmpty() bool { | ||
return o.Status == "" && (o.Code == "" || o.Code == "0") && o.Type == "" && o.Note == "" | ||
} | ||
|
||
func (o *AandaError) ToError() error { | ||
var msgs []string | ||
for _, s := range []string{o.Type, o.Note} { | ||
if s != "" { | ||
msgs = append(msgs, s) | ||
} | ||
} | ||
|
||
return errors.New(strings.Join(msgs, "; ")) | ||
} | ||
|
||
func (o *AandaError) Error() string { | ||
return fmt.Sprintf("[%s] %d - %s; %s", o.Status, o.Code, o.Type, o.Note) | ||
return fmt.Sprintf("[%s] %s - %s; %s", o.Status, o.Code, o.Type, o.Note) | ||
} | ||
|
||
type AandaErrorMsg struct { | ||
Err string `json:"error"` | ||
} | ||
|
||
func (o *AandaErrorMsg) IsEmpty() bool { | ||
return o.Err == "" | ||
} | ||
|
||
func (o *AandaErrorMsg) ToError() error { | ||
return errors.New(o.Err) | ||
} | ||
|
||
func (o *AandaErrorMsg) Error() string { | ||
return o.Err | ||
} |
Oops, something went wrong.