Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 0421d54

Browse files
committed
api, cypress, live: Add cypress tests for live databases
1 parent 40c1ef3 commit 0421d54

File tree

7 files changed

+405
-5
lines changed

7 files changed

+405
-5
lines changed

api/handlers.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func columnsHandler(w http.ResponseWriter, r *http.Request) {
157157
}
158158
}
159159
if !tableOrViewFound {
160-
jsonErr(w, "Provided table or view name doesn't exist in this database", http.StatusInternalServerError)
160+
jsonErr(w, "Provided table or view name doesn't exist in this database", http.StatusBadRequest)
161161
return
162162
}
163163

@@ -186,6 +186,14 @@ func columnsHandler(w http.ResponseWriter, r *http.Request) {
186186
return
187187
}
188188
if resp.Error != "" {
189+
if resp.ErrCode == com.AMQPRequestedTableNotPresent {
190+
// The AMQP backend said the requested table name isn't in the database. So, user error rather than
191+
// an "internal server error"
192+
jsonErr(w, com.AMQPErrorString(resp.ErrCode), http.StatusBadRequest)
193+
return
194+
}
195+
196+
// Some other error occurred, so pass it back to the user
189197
err = errors.New(resp.Error)
190198
jsonErr(w, err.Error(), http.StatusInternalServerError)
191199
return

common/errorcodes.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package common
2+
3+
// A set of error codes returned by the AMQP back end. We use these so we can
4+
// change the user facing text as desired without having to worry about
5+
// potentially breaking the AMQP communication interface
6+
7+
type AMQPErrorCode int
8+
9+
const (
10+
AMQPNoError AMQPErrorCode = iota
11+
AMQPRequestedTableNotPresent
12+
)
13+
14+
func AMQPErrorString(errCode AMQPErrorCode) string {
15+
switch errCode {
16+
case AMQPNoError:
17+
return "no error"
18+
case AMQPRequestedTableNotPresent:
19+
return "Provided table or view name doesn't exist in this database"
20+
default:
21+
return "unknown error"
22+
}
23+
}

common/live.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type LiveDBColumnsResponse struct {
3131
Node string `json:"node"`
3232
Columns []sqlite.Column `json:"columns"`
3333
Error string `json:"error"`
34+
ErrCode AMQPErrorCode `json:"error_code"`
3435
}
3536

3637
// LiveDBErrorResponse holds just the node name and any error message used in responses by our AMQP backend

common/sqlite.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ func SQLiteExecuteQueryLive(baseDir, dbOwner, dbName, loggedInUser, query string
972972
}
973973

974974
// SQLiteGetColumnsLive is used by our AMQP backend nodes to retrieve the list of columns from a SQLite database
975-
func SQLiteGetColumnsLive(baseDir, dbOwner, dbName, table string) (columns []sqlite.Column, err error) {
975+
func SQLiteGetColumnsLive(baseDir, dbOwner, dbName, table string) (columns []sqlite.Column, err error, errCode AMQPErrorCode) {
976976
// Open the database on the local node
977977
var sdb *sqlite.Conn
978978
sdb, err = OpenSQLiteDatabaseLive(baseDir, dbOwner, dbName)
@@ -995,6 +995,7 @@ func SQLiteGetColumnsLive(baseDir, dbOwner, dbName, table string) (columns []sql
995995
}
996996
if !tableOrViewFound {
997997
err = errors.New("Provided table or view name doesn't exist in this database")
998+
errCode = AMQPRequestedTableNotPresent
998999
return
9991000
}
10001001

0 commit comments

Comments
 (0)