ekyc

Electronic KYC process with uploading ID document using OAuth 2.1 (experimental)
Log | Files | Refs | README | LICENSE

error.ts (807B)


      1 import {
      2   EntityLocked,
      3   RepositoryError,
      4 } from "../../core/application/repository_error.ts";
      5 import { ConnectionError, PostgresError, TransactionError } from "$postgres";
      6 
      7 export function mapError(cause: unknown): Error {
      8   if (cause instanceof TransactionError) {
      9     if (cause.cause) {
     10       return mapError(cause.cause);
     11     }
     12     return new EntityLocked({ cause });
     13   }
     14   if (cause instanceof RepositoryError) {
     15     return cause;
     16   }
     17   if (cause instanceof ConnectionError) {
     18     return new RepositoryError("connection failure", { cause });
     19   }
     20   if (!(cause instanceof PostgresError)) {
     21     return new RepositoryError(undefined, { cause });
     22   }
     23   if (["23505", "23P01"].includes(cause.fields.code)) {
     24     throw new EntityLocked({ cause });
     25   }
     26   return new RepositoryError(undefined, { cause });
     27 }