diff --git a/sql/error.go b/sql/error.go index 0206bc98..d70ee542 100644 --- a/sql/error.go +++ b/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 diff --git a/sql/options.go b/sql/options.go index 714d5af4..ba085bc1 100644 --- a/sql/options.go +++ b/sql/options.go @@ -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