Aborting during pre-processing with custom status code


This wiki page suggests it’s possible to stop execution in server side scripting and return a custom error:
// Stop execution and return a specific status code
if (event.resource !== “test”) {
event.response.status_code = 400;
event.response.content = {“error”: “Invalid resource requested.”};

However, this functionality seems to exist only during post-processing, see this wiki page
The response resource contains the data being sent back to the client from the request.
Note: This resource is only available/relevant on post-process event and script service scripts.

So, in practice, it’s only possible to stop execution with a custom status code AFTER the database operation has already completed. Not very useful in case we want to prevent a PATCH or DELETE, the harm has already been done.

How can I return a 400 status code before the database operation completes? Especially since PATCH and DELETE don’t seem to be affected by record level filtering using roles and filters, it’s thus necessary to code access rules in pre-processing scripts.