From c2f98cb91ac6ebdba91d22c07063da1c08dd0d3e Mon Sep 17 00:00:00 2001 From: danylo-safonov-solid Date: Thu, 21 Sep 2023 22:19:40 +0300 Subject: [PATCH] upd --- example/lib/main.dart | 5 ++++- lib/deno_postgres_interop.dart | 1 + lib/src/errors/postgres_error.dart | 6 ++++++ lib/src/errors/transaction_error.dart | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 lib/src/errors/postgres_error.dart create mode 100644 lib/src/errors/transaction_error.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 8544d9e..5fc9218 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -34,12 +34,15 @@ ${result.rowDescription?.columns.map((e) => ' name = ${e.name}').join('\n')} ...result.rows.map(rowToPrettyString), ].join('\n\n'), ); - } on JSError catch (e) { + } on TransactionError catch (e) { await client.end(); return Response(''' ${e.name} ${e.cause} + ${e.cause.name} + ${e.cause.cause} + ${e.cause.message} ${e.message} $e '''); diff --git a/lib/deno_postgres_interop.dart b/lib/deno_postgres_interop.dart index adabff9..504ee77 100644 --- a/lib/deno_postgres_interop.dart +++ b/lib/deno_postgres_interop.dart @@ -9,6 +9,7 @@ export 'src/command_type.dart'; export 'src/connection.dart'; export 'src/connection_options.dart'; export 'src/encoded_arg.dart'; +export 'src/errors/transaction_error.dart'; export 'src/isolation_level.dart'; export 'src/notice.dart'; export 'src/partial/partial_connection_options.dart'; diff --git a/lib/src/errors/postgres_error.dart b/lib/src/errors/postgres_error.dart new file mode 100644 index 0000000..3af19e6 --- /dev/null +++ b/lib/src/errors/postgres_error.dart @@ -0,0 +1,6 @@ +import 'dart:js_interop'; + +import 'package:deno_postgres_interop/src/errors/js_error.dart'; + +@JS() +class PostgresError extends JSError {} diff --git a/lib/src/errors/transaction_error.dart b/lib/src/errors/transaction_error.dart new file mode 100644 index 0000000..c783ddc --- /dev/null +++ b/lib/src/errors/transaction_error.dart @@ -0,0 +1,17 @@ +import 'dart:js_interop'; + +import 'package:deno_postgres_interop/src/errors/js_error.dart'; +import 'package:deno_postgres_interop/src/errors/postgres_error.dart'; + +/// [deno-postgres@v0.17.0/TransactionError](https://deno.land/x/postgres@v0.17.0/client/error.ts?s=TransactionError). +@JS() +class TransactionError { + /// [js/Error/cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause). + external PostgresError get cause; + + /// [js/Error/message](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message). + external String get message; + + /// [js/Error/name](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name). + external String get name; +}