Skip to main content

IsPgErrorWithCode

Checks if a given error is a PostgreSQL error with a specific error code.

def IsPgErrorWithCode(
err: error,
code: string
) - > bool

Checks if a given error is a PostgreSQL error with a specific error code. This function is useful for handling database-specific errors and implementing custom error logic based on PostgreSQL error codes.

Parameters

NameTypeDescription
errerrorThe error object to check. This should be an error that might potentially be a PostgreSQL error.
codestringThe PostgreSQL error code to compare against. This code is typically a 5-character SQLSTATE code.

Returns

TypeDescription
boolTrue if the error is a PostgreSQL error and its code matches the provided code, otherwise False.