Skip to content
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

respond with 500 if no payment sent #251

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion controllers_v2/keysend.ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (controller *KeySendController) MultiKeySend(c echo.Context) error {
result := &MultiKeySendResponseBody{
Keysends: []KeySendResult{},
}
singleSuccesfulPayment := false
for _, keysend := range reqBody.Keysends {
keysend := keysend
res, err := controller.SingleKeySend(c, &keysend, userID)
Expand All @@ -125,8 +126,13 @@ func (controller *KeySendController) MultiKeySend(c echo.Context) error {
result.Keysends = append(result.Keysends, KeySendResult{
Keysend: res,
})
singleSuccesfulPayment = true
}
return c.JSON(http.StatusOK, result)
status := http.StatusOK
if !singleSuccesfulPayment {
status = http.StatusInternalServerError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a correct HTTP status code?
internal server error indicates it's an exception an unexpected bug in our system

payments might fail because the recipient can not receive anything.

maybe a 422 - Unprocessable Entity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would deserve it's own PR as we would need to change it everywhere we're making a payment. I'd rather have it consistent for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we return a 500 if a payment fails? damn, also not a good http cititzen.

}
return c.JSON(status, result)
}

func (controller *KeySendController) SingleKeySend(c echo.Context, reqBody *KeySendRequestBody, userID int64) (result *KeySendResponseBody, resp *responses.ErrorResponse) {
Expand Down