Interceptor question. I am using the preProcess in...
# box-products
w
Interceptor question. I am using the preProcess interceptor a lot, and now I am getting some errors on reinits, because it can’t find some methods. Which probably is happening because some
quick
based service is not ready yet on my reinit request. A work around would be easy but I was wondering: are coldbox modules ready when preProcess is fired for the first time?
b
When the actual interception point fires, yes.
My first thought is perhaps the request erroring is not the one issuing the reinit
w
This is what’s happening.
The function [newEntity] does not exist in the Object.
This is interesting because it is a quick service which should always have this method. Probably is is just trying a provider. The error is only happening in my reinit call. If I try again a second time, most of the time there will not be an error. If I try to reinit from an authenticated user I will get an error, if I try to reinitialize from an unauthenticad user no errors.
Copy code
modules/quick/models/BaseService.cfc in onMissingMethod at line 55
		public any function onMissingMethod( required string missingMethodName, struct missingMethodArguments = {} ) {
			return invoke(
				variables.entity.newEntity(),
				missingMethodName,
				missingMethodArguments
models/auth/UserService2.cfc
in
retrieveUserById
at line
202
modules/cbsecurity/modules/cbauth/models/AuthenticationService.cfc
in
getUser
at line
163
coldbox/system/ioc/Provider.cfc
in
onMissingMethod
at line
110
models/utils/SecurityProxy.cfc
in
getUsername
at line
41
coldbox/system/ioc/Provider.cfc
in
onMissingMethod
at line
110
interceptors/PrepareRcInterceptor.cfc
in
preProcess
at line
30
My interceptor is calling some securityproxy which has an injected cbauth service. I am calling
Copy code
return auth.isLoggedIn() ? auth.getUser().getId() : "--none--";
here and auth.isLoggedIn is just a call to
Copy code
return variables.sessionStorage.exists( variables.USER_ID_KEY );
I guess the sessionstorage is not cleared yet, because the reinit call has not finished yet. Because it is not cleared yet it is trying to get a user in the middle of a reinit, which leads to unreliable results and errors. I just shouldn’t ask for some user state in the middle of a reinit, but it happens in ALL requests because this is a onPreProcess interception. Since I only want to know a username and id or return some default value if there’s no authenticated user yet I wrapped these calls in a try catch now and return the defaults there. I could also protect this block of code by checking for a reinit key and return the defaults. Problem solved for now. Reinit on production is tricky. Most of the time we just restart the whole lucee server on a new deployment, but this is a system with multiple apps