|
28 | 28 | import io.netty.util.ReferenceCountUtil;
|
29 | 29 | import io.netty.util.internal.logging.InternalLogger;
|
30 | 30 | import io.netty.util.internal.logging.InternalLoggerFactory;
|
| 31 | +import io.r2dbc.postgresql.api.ErrorDetails; |
| 32 | +import io.r2dbc.postgresql.api.PostgresqlException; |
31 | 33 | import io.r2dbc.postgresql.message.backend.BackendKeyData;
|
32 | 34 | import io.r2dbc.postgresql.message.backend.BackendMessage;
|
33 | 35 | import io.r2dbc.postgresql.message.backend.BackendMessageDecoder;
|
|
88 | 90 | */
|
89 | 91 | public final class ReactorNettyClient implements Client {
|
90 | 92 |
|
| 93 | + static final String CONNECTION_FAILURE = "08006"; |
| 94 | + |
91 | 95 | private static final Logger logger = Loggers.getLogger(ReactorNettyClient.class);
|
92 | 96 |
|
93 | 97 | private static final boolean DEBUG_ENABLED = logger.isDebugEnabled();
|
@@ -535,38 +539,70 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
|
535 | 539 |
|
536 | 540 | }
|
537 | 541 |
|
538 |
| - static class PostgresConnectionClosedException extends R2dbcNonTransientResourceException { |
| 542 | + static class PostgresConnectionClosedException extends R2dbcNonTransientResourceException implements PostgresqlException { |
| 543 | + |
| 544 | + private final ErrorDetails errorDetails; |
539 | 545 |
|
540 | 546 | public PostgresConnectionClosedException(String reason) {
|
541 |
| - super(reason); |
| 547 | + super(reason, CONNECTION_FAILURE, 0, (String) null); |
| 548 | + this.errorDetails = ErrorDetails.fromCodeAndMessage(CONNECTION_FAILURE, reason); |
542 | 549 | }
|
543 | 550 |
|
544 | 551 | public PostgresConnectionClosedException(String reason, @Nullable Throwable cause) {
|
545 |
| - super(reason, cause); |
| 552 | + super(reason, CONNECTION_FAILURE, 0, null, cause); |
| 553 | + this.errorDetails = ErrorDetails.fromCodeAndMessage(CONNECTION_FAILURE, reason); |
| 554 | + } |
| 555 | + |
| 556 | + @Override |
| 557 | + public ErrorDetails getErrorDetails() { |
| 558 | + return this.errorDetails; |
546 | 559 | }
|
547 | 560 |
|
548 | 561 | }
|
549 | 562 |
|
550 |
| - static class PostgresConnectionException extends R2dbcNonTransientResourceException { |
| 563 | + static class PostgresConnectionException extends R2dbcNonTransientResourceException implements PostgresqlException { |
| 564 | + |
| 565 | + private final static ErrorDetails ERROR_DETAILS = ErrorDetails.fromCodeAndMessage(CONNECTION_FAILURE, "An I/O error occurred while sending to the backend or receiving from the backend"); |
551 | 566 |
|
552 | 567 | public PostgresConnectionException(Throwable cause) {
|
553 |
| - super(cause); |
| 568 | + super(ERROR_DETAILS.getMessage(), ERROR_DETAILS.getCode(), 0, null, cause); |
| 569 | + } |
| 570 | + |
| 571 | + @Override |
| 572 | + public ErrorDetails getErrorDetails() { |
| 573 | + return ERROR_DETAILS; |
554 | 574 | }
|
555 | 575 |
|
556 | 576 | }
|
557 | 577 |
|
558 |
| - static class RequestQueueException extends R2dbcTransientResourceException { |
| 578 | + static class RequestQueueException extends R2dbcTransientResourceException implements PostgresqlException { |
| 579 | + |
| 580 | + private final ErrorDetails errorDetails; |
559 | 581 |
|
560 | 582 | public RequestQueueException(String message) {
|
561 |
| - super(message); |
| 583 | + super(message, CONNECTION_FAILURE, 0, (String) null); |
| 584 | + this.errorDetails = ErrorDetails.fromCodeAndMessage(CONNECTION_FAILURE, message); |
| 585 | + } |
| 586 | + |
| 587 | + @Override |
| 588 | + public ErrorDetails getErrorDetails() { |
| 589 | + return this.errorDetails; |
562 | 590 | }
|
563 | 591 |
|
564 | 592 | }
|
565 | 593 |
|
566 |
| - static class ResponseQueueException extends R2dbcNonTransientResourceException { |
| 594 | + static class ResponseQueueException extends R2dbcNonTransientResourceException implements PostgresqlException { |
| 595 | + |
| 596 | + private final ErrorDetails errorDetails; |
567 | 597 |
|
568 | 598 | public ResponseQueueException(String message) {
|
569 |
| - super(message); |
| 599 | + super(message, CONNECTION_FAILURE, 0, (String) null); |
| 600 | + this.errorDetails = ErrorDetails.fromCodeAndMessage(CONNECTION_FAILURE, message); |
| 601 | + } |
| 602 | + |
| 603 | + @Override |
| 604 | + public ErrorDetails getErrorDetails() { |
| 605 | + return this.errorDetails; |
570 | 606 | }
|
571 | 607 |
|
572 | 608 | }
|
|
0 commit comments