(error: DatabaseError)
| 14 | } |
| 15 | |
| 16 | function mapDriverError(error: DatabaseError): MappedError { |
| 17 | switch (error.code) { |
| 18 | case '22001': |
| 19 | return { |
| 20 | kind: 'LengthMismatch', |
| 21 | column: error.details.column, |
| 22 | } |
| 23 | case '22003': |
| 24 | return { |
| 25 | kind: 'ValueOutOfRange', |
| 26 | cause: error.message, |
| 27 | } |
| 28 | case '22P02': |
| 29 | return { |
| 30 | kind: 'InvalidInputValue', |
| 31 | message: error.message, |
| 32 | } |
| 33 | case '23505': { |
| 34 | const fields = error.details.detail |
| 35 | ?.match(/Key \(([^)]+)\)/) |
| 36 | ?.at(1) |
| 37 | ?.split(', ') |
| 38 | return { |
| 39 | kind: 'UniqueConstraintViolation', |
| 40 | constraint: fields !== undefined ? { fields } : undefined, |
| 41 | } |
| 42 | } |
| 43 | case '23502': { |
| 44 | const fields = error.details.detail |
| 45 | ?.match(/Key \(([^)]+)\)/) |
| 46 | ?.at(1) |
| 47 | ?.split(', ') |
| 48 | return { |
| 49 | kind: 'NullConstraintViolation', |
| 50 | constraint: fields !== undefined ? { fields } : undefined, |
| 51 | } |
| 52 | } |
| 53 | case '23503': { |
| 54 | let constraint: { fields: string[] } | { index: string } | undefined |
| 55 | |
| 56 | if (error.details.column) { |
| 57 | constraint = { fields: [error.details.column] } |
| 58 | } else if (error.details.constraint) { |
| 59 | constraint = { index: error.details.constraint } |
| 60 | } |
| 61 | |
| 62 | return { |
| 63 | kind: 'ForeignKeyConstraintViolation', |
| 64 | constraint, |
| 65 | } |
| 66 | } |
| 67 | case '3D000': |
| 68 | return { |
| 69 | kind: 'DatabaseDoesNotExist', |
| 70 | db: error.message.split(' ').at(1)?.split('"').at(1), |
| 71 | } |
| 72 | case '28000': |
| 73 | return { |
no outgoing calls
no test coverage detected