Skip to content

Commit

Permalink
fix: show transactions with envelopes error to user when updating acc…
Browse files Browse the repository at this point in the history
…ount (#831)
  • Loading branch information
morremeyer authored Nov 9, 2023
1 parent 33312d0 commit c40a7ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/httperrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func DBError(c *gin.Context, err error) ErrorStatus {
return ErrorStatus{Status: http.StatusBadRequest, Err: err}
}

// Account cannot be on budget because transactions have envelopes
if strings.Contains(err.Error(), "the account cannot be set to on budget because") {
return ErrorStatus{Status: http.StatusBadRequest, Err: err}
}

// Account name must be unique per Budget
if strings.Contains(err.Error(), "UNIQUE constraint failed: accounts.name, accounts.budget_id") {
return ErrorStatus{Status: http.StatusBadRequest, Err: errors.New("the account name must be unique for the budget")}
Expand Down
1 change: 1 addition & 0 deletions pkg/httperrors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func TestDatabaseErrorMessages(t *testing.T) {
msg string
}{
{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"},
{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"},
{http.StatusBadRequest, "CHECK constraint failed: source_destination_different", "source and destination accounts for a transaction must be different"},
{http.StatusBadRequest, "UNIQUE constraint failed: accounts.name, accounts.budget_id", "the account name must be unique for the budget"},
{http.StatusBadRequest, "UNIQUE constraint failed: categories.name, categories.budget_id", "the category name must be unique for the budget"},
Expand Down

0 comments on commit c40a7ce

Please sign in to comment.