Skip to content

Commit

Permalink
Errors: add our own error types.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmersnoeck committed Mar 17, 2017
1 parent 1c904a0 commit 0c2445a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package aiven

import "errors"

var (
ErrNoResponseData = errors.New("No response data available")
ErrInvalidHost = errors.New("Host doesn't isn't in the correct format: `hostname:port`")
)
4 changes: 2 additions & 2 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (h *ProjectsHandler) List() ([]*Project, error) {

func parseProjectResponse(bts []byte) (*Project, error) {
if bts == nil {
return nil, errors.New("No response data available")
return nil, ErrNoResponseData
}

var rsp *ProjectResponse
Expand All @@ -114,7 +114,7 @@ func parseProjectResponse(bts []byte) (*Project, error) {
}

if rsp == nil {
return nil, errors.New("No response data available")
return nil, ErrNoResponseData
}

if rsp.Errors != nil && len(rsp.Errors) != 0 {
Expand Down
6 changes: 3 additions & 3 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ func (s *Service) Port() (string, error) {
}

func getHostPort(uri string) (string, string, error) {
url, err := url.Parse(uri)
hostUrl, err := url.Parse(uri)
if err != nil {
return "", "", err
}

sp := strings.Split(url.Host, ":")
sp := strings.Split(hostUrl.Host, ":")
if len(sp) != 2 {
return "", "", errors.New("Host doesn't exist out of hostname:port")
return "", "", ErrInvalidHost
}

return sp[0], sp[1], nil
Expand Down
2 changes: 1 addition & 1 deletion service_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (h *ServiceUsersHandler) Create(project, service string, req CreateServiceU
}

if rsp == nil {
return nil, errors.New("No response data available")
return nil, ErrNoResponseData
}

if rsp.Errors != nil && len(rsp.Errors) != 0 {
Expand Down

0 comments on commit 0c2445a

Please sign in to comment.