-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dp): return 409 in CRUD when cbsd serial number exists
- Loading branch information
Wojciech Sadowy
committed
Apr 6, 2022
1 parent
bf16d6a
commit e7bf1f1
Showing
11 changed files
with
147 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package sqorc | ||
|
||
import ( | ||
"magma/orc8r/lib/go/merrors" | ||
|
||
"github.com/lib/pq" | ||
"github.com/mattn/go-sqlite3" | ||
) | ||
|
||
const ( | ||
uniqueViolation = "unique_violation" | ||
) | ||
|
||
type ErrorChecker interface { | ||
GetError(error) error | ||
} | ||
|
||
type SQLiteErrorChecker struct{} | ||
|
||
type PostgresErrorChecker struct{} | ||
|
||
func (c SQLiteErrorChecker) GetError(err error) error { | ||
if e, ok := err.(sqlite3.Error); ok { | ||
switch e.Code { | ||
case sqlite3.ErrConstraint: | ||
return merrors.ErrAlreadyExists | ||
} | ||
} | ||
return err | ||
} | ||
|
||
func (c PostgresErrorChecker) GetError(err error) error { | ||
if e, ok := err.(*pq.Error); ok { | ||
switch e.Code.Name() { | ||
case uniqueViolation: | ||
return merrors.ErrAlreadyExists | ||
} | ||
} | ||
return err | ||
} |