"stack":"UInternalServerError: This is logged\n at Object.UError (urest/library/UErrors.js:7:8)\n at new <anonymous> (urest/library/UErrors.js:11:9)\n at runHandler (urest/library/Rest.js:79:22)\n at next (urest/library/Rest.js:87:4)\n at IncomingMessage.req.on.on (urest/library/JsonBodyParser.js:26:6)\n at emitNone (events.js:106:13)\n at IncomingMessage.emit (events.js:208:7)\n at endReadableNT (_stream_readable.js:1056:12)\n at _combinedTickCallback (internal/process/next_tick.js:138:11)\n at process._tickCallback (internal/process/next_tick.js:180:9)",
"message":"This is logged",
"eid":"3ccf6fadf79875f58631a8c7ecc302523b563423",
"code":"InternalServer",
"statusCode":500
}
Interceptors
Interceptors works in much the same way as middleware but act on the response before it is returned to the client.
GZIP Interceptor
The following example will check for the header "accept-encoding": "gzip" and will compress response bodies as fit.
const{Rest,JsonBodyParser}=require("urest");
const{Neutron}=require("urequest");
constapp=newRest();
app.int(Neutron.intercept());
app.pre(JsonBodyParser.middleware());
app.post("/echo",(req,res)=>res.send(req.body));
constserver=app.native().listen(1234);
Custom Interceptors
The value passed into res.send is attached as res.responseData, the following example checks for a property in the response and prevents the request if not true.