| Conditions | 10 |
| Total Lines | 28 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Complex classes like adapter.*sqlite3Adapter.ErrorHandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | package adapter |
||
| 20 | func (s *sqlite3Adapter) ErrorHandler(err error) error { |
||
| 21 | |||
| 22 | if sqliteError, ok := err.(sqlite3.Error); ok { |
||
| 23 | |||
| 24 | if sqliteError.Code == 18 { //SQLITE_TOOBIG |
||
| 25 | return sqlcommons.ValueTooLargeForColumn |
||
| 26 | |||
| 27 | } else if sqliteError.Code == 19 { //SQLITE_CONSTRAINT |
||
| 28 | if sqliteError.ExtendedCode == 787 || /*SQLITE_CONSTRAINT_FOREIGNKEY*/ |
||
| 29 | sqliteError.ExtendedCode == 1555 || /*SQLITE_CONSTRAINT_PRIMARYKEY*/ |
||
| 30 | sqliteError.ExtendedCode == 1811 { /*SQLITE_CONSTRAINT_TRIGGER*/ |
||
| 31 | return sqlcommons.IntegrityConstraintViolation |
||
| 32 | |||
| 33 | } else if sqliteError.ExtendedCode == 1299 { //SQLITE_CONSTRAINT_NOTNULL |
||
| 34 | return sqlcommons.CannotSetNullColumn |
||
| 35 | |||
| 36 | } else if sqliteError.ExtendedCode == 2067 { //SQLITE_CONSTRAINT_UNIQUE |
||
| 37 | return sqlcommons.UniqueConstraintViolation |
||
| 38 | |||
| 39 | } |
||
| 40 | } else if sqliteError.Code == 25 { //SQLITE_RANGE |
||
| 41 | return sqlcommons.InvalidNumericValue |
||
| 42 | } |
||
| 43 | |||
| 44 | return fmt.Errorf("Unhandled SQLite3 error. Code:[%s] Extended:[%s] Desc:[%s]", sqliteError.Code, sqliteError.ExtendedCode, sqliteError.Error()) |
||
| 45 | |||
| 46 | } else { |
||
| 47 | return err |
||
| 48 | } |
||
| 50 |