Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Polishing
Use specific exception for TDS protocol errors.

[#141]
  • Loading branch information
mp911de committed Feb 21, 2020
1 parent 24cf1c4 commit f8d96b3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/io/r2dbc/mssql/ExceptionFactory.java
Expand Up @@ -17,6 +17,7 @@
package io.r2dbc.mssql;

import io.r2dbc.mssql.message.Message;
import io.r2dbc.mssql.message.tds.ProtocolException;
import io.r2dbc.mssql.message.token.AbstractInfoToken;
import io.r2dbc.mssql.message.token.ErrorToken;
import io.r2dbc.mssql.message.token.InfoToken;
Expand All @@ -32,6 +33,8 @@
import io.r2dbc.spi.R2dbcTransientResourceException;
import reactor.core.publisher.SynchronousSink;

import static io.r2dbc.mssql.message.token.AbstractInfoToken.Classification.GENERAL_ERROR;

/**
* Factory for SQL Server-specific {@link R2dbcException}s.
*
Expand Down Expand Up @@ -131,6 +134,10 @@ static R2dbcException createException(AbstractInfoToken token, String sql) {
return new MssqlTransientResourceException(createExceptionDetails(token));
}

if (token.getClassification() == GENERAL_ERROR && token.getNumber() == 4002) {
return new ProtocolException(token.getMessage());
}

switch (token.getClassification()) {
case OBJECT_DOES_NOT_EXIST:
case SYNTAX_ERROR:
Expand Down Expand Up @@ -170,7 +177,7 @@ void handleErrorResponse(Message message, SynchronousSink<Message> sink) {
*
* @param message the message.
*/
Exception createException(ErrorToken message) {
RuntimeException createException(ErrorToken message) {
return createException(message, this.sql);
}

Expand Down

0 comments on commit f8d96b3

Please sign in to comment.