MCPcopy Create free account
hub / github.com/Effect-TS/effect / classifyError

Function classifyError

packages/sql/pg/src/PgClient.ts:926–966  ·  view source on GitHub ↗
(
  cause: unknown,
  message: string,
  operation: string
)

Source from the content-addressed store, hash-verified

924}
925
926const classifyError = (
927 cause: unknown,
928 message: string,
929 operation: string
930) => {
931 const props = { cause, message, operation }
932 const code = pgCodeFromCause(cause)
933 if (code !== undefined) {
934 if (code.startsWith("08")) {
935 return new ConnectionError(props)
936 }
937 if (code.startsWith("28")) {
938 return new AuthenticationError(props)
939 }
940 if (code === "42501") {
941 return new AuthorizationError(props)
942 }
943 if (code.startsWith("42")) {
944 return new SqlSyntaxError(props)
945 }
946 if (code === "23505") {
947 return new UniqueViolation({ ...props, constraint: pgConstraintFromCause(cause) })
948 }
949 if (code.startsWith("23")) {
950 return new ConstraintError(props)
951 }
952 if (code === "40P01") {
953 return new DeadlockError(props)
954 }
955 if (code === "40001") {
956 return new SerializationError(props)
957 }
958 if (code === "55P03") {
959 return new LockTimeoutError(props)
960 }
961 if (code === "57014") {
962 return new StatementTimeoutError(props)
963 }
964 }
965 return new UnknownError(props)
966}

Callers 9

makeFunction · 0.70
makeClientFunction · 0.70
onErrorFunction · 0.70
makeConectionFunction · 0.70
PgClient.tsFile · 0.70
runMethod · 0.70
executeRawMethod · 0.70
executeValuesMethod · 0.70
executeStreamMethod · 0.70

Calls 2

pgCodeFromCauseFunction · 0.70
pgConstraintFromCauseFunction · 0.70

Tested by

no test coverage detected