Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Return an ErrBadConn from the http client if the connection does not …
Browse files Browse the repository at this point in the history
…exist on the Avatica server
  • Loading branch information
F21 committed Jul 18, 2017
1 parent 89cfc1c commit 90579e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
18 changes: 9 additions & 9 deletions gen-protobuf.bat
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
SET CALCITE_VER=calcite-1.11.0
SET AVATICA_VER=rel/avatica-1.10.0

rmdir /Q /S message
rmdir /Q /S calcite-tmp
rmdir /Q /S avatica-tmp

git init calcite-tmp
cd calcite-tmp
git remote add origin https://github.com/apache/calcite/
git init avatica-tmp
cd avatica-tmp
git remote add origin https://github.com/apache/calcite-avatica/
git config core.sparsecheckout true
echo avatica/core/src/main/protobuf/* >> .git/info/sparse-checkout
git pull --depth=1 origin %CALCITE_VER%
echo calcite-avatica/core/src/main/protobuf/* >> .git/info/sparse-checkout
git pull --depth=1 origin %AVATICA_VER%

cd ..
mkdir message
protoc --proto_path=calcite-tmp/avatica/core/src/main/protobuf/ --go_out=import_path=message:message calcite-tmp/avatica/core/src/main/protobuf/*.proto
protoc --proto_path=avatica-tmp/core/src/main/protobuf/ --go_out=import_path=message:message avatica-tmp/core/src/main/protobuf/*.proto

rmdir /Q /S calcite-tmp
rmdir /Q /S avatica-tmp
16 changes: 14 additions & 2 deletions http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package avatica

import (
"bytes"
"database/sql/driver"
"fmt"
"io/ioutil"
"net/http"

"fmt"
"regexp"

avaticaMessage "github.com/Boostport/avatica/message"
"github.com/golang/protobuf/proto"
Expand All @@ -19,6 +20,10 @@ import (
"golang.org/x/net/context/ctxhttp"
)

var (
badConnRe = regexp.MustCompile(`org\.apache\.calcite\.avatica\.NoSuchConnectionException`)
)

type httpClientAuthConfig struct {
authenticationType authentication

Expand Down Expand Up @@ -176,6 +181,13 @@ func (c *httpClient) post(ctx context.Context, message proto.Message) (proto.Mes
}

if v, ok := inner.(*avaticaMessage.ErrorResponse); ok {

for _, exception := range v.Exceptions {
if badConnRe.MatchString(exception) {
return nil, driver.ErrBadConn
}
}

return nil, errorResponseToResponseError(v)
}

Expand Down

0 comments on commit 90579e7

Please sign in to comment.