3131import com .github .shyiko .mysql .binlog .io .ByteArrayInputStream ;
3232import com .github .shyiko .mysql .binlog .jmx .BinaryLogClientMXBean ;
3333import com .github .shyiko .mysql .binlog .network .AuthenticationException ;
34+ import com .github .shyiko .mysql .binlog .network .ServerException ;
3435import com .github .shyiko .mysql .binlog .network .SocketFactory ;
3536import com .github .shyiko .mysql .binlog .network .protocol .ErrorPacket ;
3637import com .github .shyiko .mysql .binlog .network .protocol .GreetingPacket ;
@@ -310,7 +311,8 @@ public void setThreadFactory(ThreadFactory threadFactory) {
310311
311312 /**
312313 * Connect to the replication stream. Note that this method blocks until disconnected.
313- * @throws AuthenticationException in case of failed authentication
314+ * @throws AuthenticationException if authentication fails
315+ * @throws ServerException if MySQL server responds with an error
314316 * @throws IOException if anything goes wrong while trying to connect
315317 */
316318 public void connect () throws IOException {
@@ -327,7 +329,7 @@ public void connect() throws IOException {
327329 }
328330 } catch (IOException e ) {
329331 throw new IOException ("Failed to connect to MySQL on " + hostname + ":" + port +
330- ". Please make sure it's running." , e );
332+ ". Please make sure it's running." , e );
331333 }
332334 GreetingPacket greetingPacket = new GreetingPacket (channel .read ());
333335 authenticate (greetingPacket .getScramble (), greetingPacket .getServerCollation ());
@@ -409,7 +411,9 @@ private void authenticate(String salt, int collation) throws IOException {
409411 if (authenticationResult [0 ] != (byte ) 0x00 /* ok */ ) {
410412 if (authenticationResult [0 ] == (byte ) 0xFF /* error */ ) {
411413 byte [] bytes = Arrays .copyOfRange (authenticationResult , 1 , authenticationResult .length );
412- throw new AuthenticationException (new ErrorPacket (bytes ).getErrorMessage ());
414+ ErrorPacket errorPacket = new ErrorPacket (bytes );
415+ throw new AuthenticationException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
416+ errorPacket .getSqlState ());
413417 }
414418 throw new AuthenticationException ("Unexpected authentication result (" + authenticationResult [0 ] + ")" );
415419 }
@@ -476,9 +480,10 @@ boolean isKeepAliveThreadRunning() {
476480 /**
477481 * Connect to the replication stream in a separate thread.
478482 * @param timeoutInMilliseconds timeout in milliseconds
479- * @throws AuthenticationException in case of failed authentication
483+ * @throws AuthenticationException if authentication fails
484+ * @throws ServerException if MySQL server responds with an error
480485 * @throws IOException if anything goes wrong while trying to connect
481- * @throws TimeoutException if client wasn't able to connect in the requested period of time
486+ * @throws TimeoutException if client was unable to connect within given time limit
482487 */
483488 public void connect (long timeoutInMilliseconds ) throws IOException , TimeoutException {
484489 final CountDownLatch countDownLatch = new CountDownLatch (1 );
@@ -553,7 +558,9 @@ private void confirmSupportOfChecksum(ChecksumType checksumType) throws IOExcept
553558 byte [] statementResult = channel .read ();
554559 if (statementResult [0 ] == (byte ) 0xFF /* error */ ) {
555560 byte [] bytes = Arrays .copyOfRange (statementResult , 1 , statementResult .length );
556- throw new IOException (new ErrorPacket (bytes ).getErrorMessage ());
561+ ErrorPacket errorPacket = new ErrorPacket (bytes );
562+ throw new ServerException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
563+ errorPacket .getSqlState ());
557564 }
558565 eventDeserializer .setChecksumType (checksumType );
559566 }
@@ -567,7 +574,8 @@ private void listenForEventPackets() throws IOException {
567574 int marker = inputStream .read ();
568575 if (marker == 0xFF ) {
569576 ErrorPacket errorPacket = new ErrorPacket (inputStream .read (packetLength - 1 ));
570- throw new IOException (errorPacket .getErrorCode () + " - " + errorPacket .getErrorMessage ());
577+ throw new ServerException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
578+ errorPacket .getSqlState ());
571579 }
572580 Event event ;
573581 try {
0 commit comments