32 lines
825 B
Go
32 lines
825 B
Go
package db
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func IsBadRequest(err error) bool {
|
|
return strings.HasPrefix(err.Error(), "bad request:")
|
|
}
|
|
|
|
func BadRequest(err string) error {
|
|
return fmt.Errorf("bad request: %s", err)
|
|
}
|
|
|
|
func BadRequestNotFound(resource, field string, value any) error {
|
|
errStr := fmt.Sprintf("%s with %s=%v not found", resource, field, value)
|
|
return BadRequest(errStr)
|
|
}
|
|
|
|
func BadRequestNotAssociated(parent, child string, parentID, childID any) error {
|
|
errStr := fmt.Sprintf("%s (ID: %v) not associated with %s (ID: %v)",
|
|
child, childID, parent, parentID)
|
|
return BadRequest(errStr)
|
|
}
|
|
|
|
func BadRequestAssociated(parent, child string, parentID, childID any) error {
|
|
errStr := fmt.Sprintf("%s (ID: %v) already associated with %s (ID: %v)",
|
|
child, childID, parent, parentID)
|
|
return BadRequest(errStr)
|
|
}
|