MySQL examples

Sending a detailed error

If a filter wants to send an error back to the client in a request filter, it can normally use the result object, e.g.:

context.result.success = false;
context.result.errorMessage = "Your query is rejected because reasons";
context.result.errorCode = 12345;

However, this mechanism does not allow you to set the SQL state of the error. If you need to do that, you need to create an Error packet and set it up:

let err = context.myutils.createPacket("ERR");

err.errorCode = 12345;

err.errorMessage = "Your request is denied";

err.sqlState = "FOO";

context.result.response = err;

There is also a quicker way to do the same thing using the context.utils object:

context.result.response = context.myutils.createErrorPacket(12345, "FOO", "Your request is denied");