THROW
THROW
statement
The THROW
statement can be used to throw an error in a place where something unexpected is happening. Execution of the query will be aborted and the error will be returned to the client.
Statement syntax
SurrealQL Syntax
THROW @error
Example usage
The following query shows example usage of this statement.
-- Throw an error
THROW "some error message";
The following query shows the THROW
statement being used to send back a custom error to the client.
-- In this example, we throw a custom error when a user provides invalid signin details
DEFINE SCOPE user SESSION 1w
SIGNIN {
LET $user = (SELECT * FROM user WHERE username = $username AND crypto::argon2::compare(password, $password));
IF !$user {
THROW "You either provided invalid credentials, or a user with the username " + <string> $username + " might not exist.";
};
RETURN $user;
};