Improve error message when unable to select NS/DB
This commit is contained in:
parent
3038b6adec
commit
cd44c77de6
2 changed files with 24 additions and 12 deletions
28
sql/error.go
28
sql/error.go
|
@ -27,14 +27,6 @@ func (e *EmptyError) Error() string {
|
|||
return fmt.Sprint("Your SQL query is empty")
|
||||
}
|
||||
|
||||
// EntryError represents an error that occured when switching access.
|
||||
type EntryError struct{}
|
||||
|
||||
// Error returns the string representation of the error.
|
||||
func (e *EntryError) Error() string {
|
||||
return fmt.Sprint("You don't have permission to access this resource")
|
||||
}
|
||||
|
||||
// QueryError represents an error that occured when switching access.
|
||||
type QueryError struct{}
|
||||
|
||||
|
@ -51,6 +43,26 @@ func (e *BlankError) Error() string {
|
|||
return fmt.Sprint("You need to specify a namespace and a database to use")
|
||||
}
|
||||
|
||||
// NSError represents an error that occured when switching access.
|
||||
type NSError struct {
|
||||
NS string
|
||||
}
|
||||
|
||||
// Error returns the string representation of the error.
|
||||
func (e *NSError) Error() string {
|
||||
return fmt.Sprintf("You don't have permission to access the '%s' namespace", e.NS)
|
||||
}
|
||||
|
||||
// DBError represents an error that occured when switching access.
|
||||
type DBError struct {
|
||||
DB string
|
||||
}
|
||||
|
||||
// Error returns the string representation of the error.
|
||||
func (e *DBError) Error() string {
|
||||
return fmt.Sprintf("You don't have permission to access the '%s' database", e.DB)
|
||||
}
|
||||
|
||||
// ParseError represents an error that occurred during parsing.
|
||||
type ParseError struct {
|
||||
Found string
|
||||
|
|
|
@ -81,8 +81,8 @@ func (o *options) ns(ns string) (err error) {
|
|||
// the necessary authentcation privileges
|
||||
// to be able to specify this namespace.
|
||||
|
||||
if o.auth["NS"] != "*" && o.auth["NS"] != ns {
|
||||
return &EntryError{}
|
||||
if o.auth.Possible.NS != "*" && o.auth.Possible.NS != ns {
|
||||
return &NSError{NS: ns}
|
||||
}
|
||||
|
||||
// Specify the NS on the context session, so
|
||||
|
@ -109,8 +109,8 @@ func (o *options) db(db string) (err error) {
|
|||
// the necessary authentcation privileges
|
||||
// to be able to specify this namespace.
|
||||
|
||||
if o.auth["DB"] != "*" && o.auth["DB"] != db {
|
||||
return &EntryError{}
|
||||
if o.auth.Possible.DB != "*" && o.auth.Possible.DB != db {
|
||||
return &DBError{DB: db}
|
||||
}
|
||||
|
||||
// Specify the DB on the context session, so
|
||||
|
|
Loading…
Reference in a new issue