-
Notifications
You must be signed in to change notification settings - Fork 726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(client): Return nil and error if endpoint is empty string #2773
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of returning nil
, the function execute can return an error if the endpoint is an empty string.
Lines 64 to 72 in 569529d
func (r *request) execute(method, path string, data interface{}) (io.ReadCloser, error) { | |
if r.endpoint[len(r.endpoint)-1:] == "/" { | |
r.endpoint = r.endpoint[:len(r.endpoint)-1] | |
} | |
u, err := url.Parse(r.endpoint + path) | |
if err != nil { | |
return nil, err | |
} |
A new error type can be exposed outside the package for this purpose:
Lines 23 to 30 in 569529d
// List of exposed errors. | |
var ( | |
ErrNotAuthorized = errors.New("miniflux: unauthorized (bad credentials)") | |
ErrForbidden = errors.New("miniflux: access forbidden") | |
ErrServerError = errors.New("miniflux: internal server error") | |
ErrNotFound = errors.New("miniflux: resource not found") | |
ErrBadRequest = errors.New("miniflux: bad request") | |
) |
Taking a quick look, I think your solution is better than mine. As long as no Client's endpoint field is used outside of a request context, it shoud work fine. I 'll try and code it, run it for a few days and then get back to you. Thanks for the suggestion! |
629bec6
to
da64ee5
Compare
Updated per your suggestion. I came up with the error name and string but happy to alter name and wording. |
Why: Passing an empty string as an endpoint to Client when instantiating a new client might seem like something that should never happen but I managed to trigger it while parsing some input files to register feeds in bulk. What: In the execute() function, check early if the endpoint is "" and then return immediately nil and a new error, named ErrEmptyEndpoint with a descriptive string
Why:
Passing an empty string as an endpoint to Client when instantiating a
new client might seem like something that should never happen but I
managed to trigger it while parsing some input files to register feeds
in bulk.
What:
In the execute() function, check early if the endpoint is "" and then
return immediately nil and a new error, named ErrWrongEndpoint with a
descriptive string
Do you follow the guidelines?