Skip to content

Commit

Permalink
add IsInvalidTextRepresentation
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed May 23, 2018
1 parent bbb2559 commit b76f476
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func contains(xs []string, x string) bool {
return false
}

// IsUniqueViolation checks is error unique_violation with given constraint,
// IsUniqueViolation checks is error an unique_violation with given constraint,
// constraint can be empty to ignore constraint name checks
func IsUniqueViolation(err error, constraint ...string) bool {
if pqErr, ok := err.(*pq.Error); ok && pqErr.Code == "23505" {
Expand All @@ -24,3 +24,11 @@ func IsUniqueViolation(err error, constraint ...string) bool {
}
return false
}

// IsInvalidTextRepresentation checks is error an invalid_text_representation
func IsInvalidTextRepresentation(err error) bool {
if pqErr, ok := err.(*pq.Error); ok && pqErr.Code == "22P02" {
return true
}
return false
}

0 comments on commit b76f476

Please sign in to comment.