diff --git a/proxy/proxy.go b/proxy/proxy.go index bed4a45..fc585f4 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -812,14 +812,13 @@ func (c *client) interceptSystemQuery(hdr *frame.Header, stmt interface{}) { } case *parser.UseStatement: if _, err := c.proxy.maybeCreateSession(hdr.Version, s.Keyspace); err != nil { + errMsg := "Proxy unable to create new session for keyspace" var cqlError *proxycore.CqlError - switch { - case errors.As(err, &cqlError): - errMsg := cqlError.Message - c.send(hdr, errMsg) - default: - c.send(hdr, &message.ServerError{ErrorMessage: "Proxy unable to create new session for keyspace"}) + if errors.As(err, &cqlError) { + // copy detailed error reason from downstream message + errMsg = cqlError.Message.GetErrorMessage() } + c.send(hdr, &message.ServerError{ErrorMessage: errMsg}) } else { c.keyspace = s.Keyspace // We might have received a quoted keyspace name in the UseStatement so remove any