getAlby / lndhub.go

Accounting wrapper for the Lightning Network. It provides separate accounts for end-users. (LndHub compatible API written in Go)
GNU General Public License v3.0
86 stars 23 forks source link

Improve bad arguments error to provide a reason #390

Open rolznz opened 1 year ago

rolznz commented 1 year ago

If an invalid request is provided it would be nice to return to the caller why the arguments were bad rather than just "bad arguments".

I am not sure of the security implications here.

https://github.com/getAlby/lndhub.go/blob/main/lib/responses/errors.go#L25

lujakob commented 1 year ago

@kiwiidb this issue doesn't seem to complex to solve. Can I give it a try?

My suggestion is to create a method that returns the BadArgumentsError and can be passed an argument to append to the already available property Message: "Bad arguments",

I would suggest to just pass the same string that is passed to Errorf

c.Logger().Errorf("Failed to load addinvoice request body: %v", err)
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)

All cases should be checked if this string contains data that should not be revealed.

Any concerns? Am I missing something?

kiwiidb commented 1 year ago

Should be good, please make a PR including an integration test and a some examples of the error JSON's in the PR description.