Skip to content

Commit

Permalink
Refactor error object
Browse files Browse the repository at this point in the history
Rename namespace
  • Loading branch information
Kyaw Myint Thein committed Sep 21, 2021
1 parent 3c58aee commit f2af773
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ var (
_errInvalidTwirpClientIdentifier = errors.New("[LuraTwirp]:invalid twirp stub")

// ErrEmptyValue is the error returned when there is no config under the namespace
ErrEmptyValue = errors.New("getting the extra config for the martian module")
_errEmptyValue = errors.New("getting the extra config for the martian module")
// ErrBadValue is the error returned when the config is not a map
ErrBadValue = errors.New("casting the extra config for the martian module")
_errBadValue = errors.New("casting the extra config for the martian module")
// ErrMarshallingValue is the error returned when the config map can not be marshalled again
ErrMarshallingValue = errors.New("marshalling the extra config for the martian module")
_errMarshallingValue = errors.New("marshalling the extra config for the martian module")
// ErrEmptyResponse is the error returned when the modifier receives a nil response
ErrEmptyResponse = errors.New("getting the http response from the request executor")
_errEmptyResponse = errors.New("getting the http response from the request executor")
)
2 changes: 1 addition & 1 deletion namespace.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package luratwirp

const (
Namespace = "github.com/kyawmyintthein/twirp-lura/martian"
Namespace = "github.com/kyawmyintthein/lura-twirp/martian"
)
10 changes: 5 additions & 5 deletions twirp.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func NewConfiguredBackendFactory(l logging.Logger, ref func(*config.Backend) cli
switch result.Err {
case nil:
return proxy.NewHTTPProxyWithHTTPExecutor(remote, HTTPRequestExecutor(result.Result, re), remote.Decoder)
case ErrEmptyValue:
case _errEmptyValue:
return proxy.NewHTTPProxyWithHTTPExecutor(remote, re, remote.Decoder)
default:
l.Error(result, remote.ExtraConfig)
Expand All @@ -162,17 +162,17 @@ func NewConfiguredBackendFactory(l logging.Logger, ref func(*config.Backend) cli
func getConfig(e config.ExtraConfig) interface{} {
cfg, ok := e[Namespace]
if !ok {
return result{nil, ErrEmptyValue}
return result{nil, _errEmptyValue}
}

data, ok := cfg.(map[string]interface{})
if !ok {
return result{nil, ErrBadValue}
return result{nil, _errBadValue}
}

raw, err := json.Marshal(data)
if err != nil {
return result{nil, ErrMarshallingValue}
return result{nil, _errMarshallingValue}
}

r, err := parse.FromJSON(raw)
Expand Down Expand Up @@ -278,7 +278,7 @@ func HTTPRequestExecutor(result *parse.Result, re client.HTTPRequestExecutor) cl
return
}
if resp == nil {
err = ErrEmptyResponse
err = _errEmptyResponse
return
}
} else if resp == nil {
Expand Down

0 comments on commit f2af773

Please sign in to comment.