|
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;
|
|
89 | 91 | */
|
90 | 92 | public final class ReactorNettyClient implements Client {
|
91 | 93 |
|
| 94 | + static final String CONNECTION_FAILURE = "08006"; |
| 95 | + |
92 | 96 | private static final Logger logger = Loggers.getLogger(ReactorNettyClient.class);
|
93 | 97 |
|
94 | 98 | private static final boolean DEBUG_ENABLED = logger.isDebugEnabled();
|
@@ -551,38 +555,70 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
|
551 | 555 |
|
552 | 556 | }
|
553 | 557 |
|
554 |
| - static class PostgresConnectionClosedException extends R2dbcNonTransientResourceException { |
| 558 | + static class PostgresConnectionClosedException extends R2dbcNonTransientResourceException implements PostgresqlException { |
| 559 | + |
| 560 | + private final ErrorDetails errorDetails; |
555 | 561 |
|
556 | 562 | public PostgresConnectionClosedException(String reason) {
|
557 |
| - super(reason); |
| 563 | + super(reason, CONNECTION_FAILURE, 0, (String) null); |
| 564 | + this.errorDetails = ErrorDetails.fromCodeAndMessage(CONNECTION_FAILURE, reason); |
558 | 565 | }
|
559 | 566 |
|
560 | 567 | public PostgresConnectionClosedException(String reason, @Nullable Throwable cause) {
|
561 |
| - super(reason, cause); |
| 568 | + super(reason, CONNECTION_FAILURE, 0, null, cause); |
| 569 | + this.errorDetails = ErrorDetails.fromCodeAndMessage(CONNECTION_FAILURE, reason); |
| 570 | + } |
| 571 | + |
| 572 | + @Override |
| 573 | + public ErrorDetails getErrorDetails() { |
| 574 | + return this.errorDetails; |
562 | 575 | }
|
563 | 576 |
|
564 | 577 | }
|
565 | 578 |
|
566 |
| - static class PostgresConnectionException extends R2dbcNonTransientResourceException { |
| 579 | + static class PostgresConnectionException extends R2dbcNonTransientResourceException implements PostgresqlException { |
| 580 | + |
| 581 | + 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"); |
567 | 582 |
|
568 | 583 | public PostgresConnectionException(Throwable cause) {
|
569 |
| - super(cause); |
| 584 | + super(ERROR_DETAILS.getMessage(), ERROR_DETAILS.getCode(), 0, null, cause); |
| 585 | + } |
| 586 | + |
| 587 | + @Override |
| 588 | + public ErrorDetails getErrorDetails() { |
| 589 | + return ERROR_DETAILS; |
570 | 590 | }
|
571 | 591 |
|
572 | 592 | }
|
573 | 593 |
|
574 |
| - static class RequestQueueException extends R2dbcTransientResourceException { |
| 594 | + static class RequestQueueException extends R2dbcTransientResourceException implements PostgresqlException { |
| 595 | + |
| 596 | + private final ErrorDetails errorDetails; |
575 | 597 |
|
576 | 598 | public RequestQueueException(String message) {
|
577 |
| - 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; |
578 | 606 | }
|
579 | 607 |
|
580 | 608 | }
|
581 | 609 |
|
582 |
| - static class ResponseQueueException extends R2dbcNonTransientResourceException { |
| 610 | + static class ResponseQueueException extends R2dbcNonTransientResourceException implements PostgresqlException { |
| 611 | + |
| 612 | + private final ErrorDetails errorDetails; |
583 | 613 |
|
584 | 614 | public ResponseQueueException(String message) {
|
585 |
| - super(message); |
| 615 | + super(message, CONNECTION_FAILURE, 0, (String) null); |
| 616 | + this.errorDetails = ErrorDetails.fromCodeAndMessage(CONNECTION_FAILURE, message); |
| 617 | + } |
| 618 | + |
| 619 | + @Override |
| 620 | + public ErrorDetails getErrorDetails() { |
| 621 | + return this.errorDetails; |
586 | 622 | }
|
587 | 623 |
|
588 | 624 | }
|
|
0 commit comments