Skip to content

Commit c40a7ce

Browse files
authored
fix: show transactions with envelopes error to user when updating account (#831)
1 parent 33312d0 commit c40a7ce

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

pkg/httperrors/errors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ func DBError(c *gin.Context, err error) ErrorStatus {
7070
return ErrorStatus{Status: http.StatusBadRequest, Err: err}
7171
}
7272

73+
// Account cannot be on budget because transactions have envelopes
74+
if strings.Contains(err.Error(), "the account cannot be set to on budget because") {
75+
return ErrorStatus{Status: http.StatusBadRequest, Err: err}
76+
}
77+
7378
// Account name must be unique per Budget
7479
if strings.Contains(err.Error(), "UNIQUE constraint failed: accounts.name, accounts.budget_id") {
7580
return ErrorStatus{Status: http.StatusBadRequest, Err: errors.New("the account name must be unique for the budget")}

pkg/httperrors/errors_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func TestDatabaseErrorMessages(t *testing.T) {
172172
msg string
173173
}{
174174
{http.StatusBadRequest, "availability month must not be earlier than the month of the transaction, transaction date: 2023-10-22, available month 2023-09", "availability month must not be earlier than the month of the transaction, transaction date: 2023-10-22, available month 2023-09"},
175+
{http.StatusBadRequest, "the account cannot be set to on budget because the following transactions have an envelope set", "the account cannot be set to on budget because the following transactions have an envelope set"},
175176
{http.StatusBadRequest, "CHECK constraint failed: source_destination_different", "source and destination accounts for a transaction must be different"},
176177
{http.StatusBadRequest, "UNIQUE constraint failed: accounts.name, accounts.budget_id", "the account name must be unique for the budget"},
177178
{http.StatusBadRequest, "UNIQUE constraint failed: categories.name, categories.budget_id", "the category name must be unique for the budget"},

0 commit comments

Comments
 (0)