The result object

Whenever a filter is executed, it can always depend on an object named result in the context variable:

const res = context.result;

This result object has the following fields that your code can modify:

success: boolean, true by default. If set to false, this indicates to the engine that this filter does not wish normal processing to continue. The exact meaning depends on the type of filter, check the documentation for details.

// We're not happy, let the engine know it
context.result.success = false;


errorMessage: string, empty by default. If you set success to false, we highly recommend you set errorMessage to some string that explains why. This will make debugging easier, and the error message will usually find its way back to the client -- again, that depends on the filter type.

context.result.success = false;
context.result.errorMessage = "Your update has been rejected because reasons";


errorCode: number, 0 by default. If you set success to false, you can also set errorCode to a number that will be sent back to the client, if the database protocol supports it.

context.result.success = false;
context.result.errorMessage = "Your update has been rejected because reasons";

context.result.errorCode = 12345;


closeConnection: boolean, false by default. If your logic wants to not just send an error back to the client, but actually terminate the connection, set this to true.

if (context.packet.getParameter("user") === "jdoe") {
context.result.success = false;
context.result.errorMessage = "We don't like John Doe";
context.result.closeConnection = true;
}


skip: boolean, false by default. If set to true, Gallium Data will simply drop this packet. Use this with caution -- dropping a result set row is usually OK, but dropping other kinds of packets can easily lead to a protocol error.

if (pkt.responseCode > 0) {

context.result.skip = true;

}


response: object, null by default. If you set this variable to a packet object, then the engine will forward that packet rather than the current packet. This is an advanced feature.

context.result.response = myPacket;