mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
all: use more go-ish error for constraint failures
This commit is contained in:
@@ -6,7 +6,7 @@ in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
{{/* custom errors and errors handlers for sql dialects */}}
|
||||
{{ define "dialect/sql/errors" }}
|
||||
func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
@@ -17,11 +17,11 @@ func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) {
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ErrConstraintFailed{msg, err}, true
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
Reference in New Issue
Block a user