mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
fix: avoid leaking raw postgres error details in duplicate key response (#2538)
This commit is contained in:
parent
459b825cfb
commit
0c24ab84c1
1 changed files with 7 additions and 1 deletions
|
|
@ -6,10 +6,12 @@ import (
|
|||
"github.com/getAlby/hub/constants"
|
||||
"github.com/getAlby/hub/nip47/models"
|
||||
"github.com/getAlby/hub/transactions"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func mapNip47Error(err error) *models.Error {
|
||||
code := constants.ERROR_INTERNAL
|
||||
message := err.Error()
|
||||
if errors.Is(err, transactions.NewNotFoundError()) {
|
||||
code = constants.ERROR_NOT_FOUND
|
||||
}
|
||||
|
|
@ -19,9 +21,13 @@ func mapNip47Error(err error) *models.Error {
|
|||
if errors.Is(err, transactions.NewQuotaExceededError()) {
|
||||
code = constants.ERROR_QUOTA_EXCEEDED
|
||||
}
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
// avoid leaking raw driver/SQL error details (e.g. constraint names) to NWC apps
|
||||
message = gorm.ErrDuplicatedKey.Error()
|
||||
}
|
||||
|
||||
return &models.Error{
|
||||
Code: code,
|
||||
Message: err.Error(),
|
||||
Message: message,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue