Hello everyone! Need some help hunting down cause ...
# box-products
z
Hello everyone! Need some help hunting down cause of error in a rest api. The route is suppose to receive an email address then send a reset password email to that email address. The email sends fine and looks fine, but the route returns a 500 internal server error. The stack trace says error is missing include could not find template //views/auth/createPasswordChangeRequest which shouldn't be a view at all, it's a service function. it almost seems like as soon as it renders the email it stops trying to return an api request, and instead a view? I have found 2 things that seem to fix it. if I change from coldbox.system.RestHandler to a custom handler, it seems to work fine.
Copy code
// *** this line below **
component extends="coldbox.system.RestHandler" {
  function createPasswordChangeRequest(event,rc,prc){       

        //Authenticate User
        var result  =  userService.createPasswordChangeRequest(argumentCollection=rc);
       
        //Configure Results
        prc.response.setData(queryToArray.convert(result,"lowercase"));
    };
}
that's my handler or if I change in our email service this Renderer.renderLayout to just a string I don't get the error either.
Copy code
component 
	threadSafe	= "true"
	output		= false
	hint  		= "mail service help to mailService@cbmailservices" {

	property name="cbMailService" 	inject="mailService@cbmailservices";
	property name="Renderer"     	inject="Renderer@coldbox";
	property name="ENVIRONMENT" 		inject="coldbox:setting:ENVIRONMENT";
    property name="CONFIG"              inject="coldbox:configSettings";

	emailService function init(){
		return this;
	}

	public struct function send(required string layoutName, required string viewName, required struct settings, string type) {

		// Create mail service object
		var emailPayload = cbMailService.newMail();

		// Set the settings
		emailPayload.setTo(<http://ARGUMENTS.settings.to|ARGUMENTS.settings.to>);
		emailPayload.setFrom(ARGUMENTS.settings.from);
		emailPayload.setSubject(ARGUMENTS.settings.subject);

// ******** these lines *****
emailPayload.setText(Renderer.renderLayout(layout="email/referencecenter.text",view="email/"&ARGUMENTS.viewName&".text"));
			emailPayload.setHtml(Renderer.renderLayout(layout="email/referencecenter.html",view="email/"&ARGUMENTS.viewName&".html"));
//*********************
var result = cbMailService.send(emailPayload);

		return result;
	}
any insight would be super appreciated I would love to be able to use the coldbox.system.resthandler and renderer.renderlayout together but I keep getting that error response.
p
Your handler should be
event.response.setData(queryToArray.convert(result,"lowercase"));
but you just are setting the private scope (prc).
z
just gave it a try and still getting that same missing include error.
p
Did you reinit your app and all that?
z
I just doubled checked reinit'd and tried again, I did have to do event.getResponse().setData but still getting same missing include error.
b
It would appear the CodBox request is trying to go through the normal flow of including the convention view.
☝🏾 1
Since this is using the base rest handler and returning an array, I would expect the default behavior to be a JSON data rendering.
I don't understand what you mean when you say
or if I change in our email service this Renderer.renderLayout to just a string I don't get the error either.
Also, if you comment out the userservice stuff and just set a dummy array data, are you saying it works fine?
It sounds like you're saying that any direct usage of the renderer in the request, is changing ColdBox's render data settings. Is that correct?
@Zac Warner
z
yes so if I don't call the Renderer.renderlayout. it works fine
b
Can you compare rc and prc before and after to see what changes?
z
or if I don't use the coldbox.system.RestHandler. it seems to work
d
@bdw429s
z
looks like a currentLayout gets added to prc after Renderer.renderlayout
b
If you manually remove that, does it work?
If so, I think we have enough to put I a ticket
d
After removing currentLayout it still errors out.
b
Well, find out what else is getting set 😀
It pretty much has to be in the request scope or the requestcontext
z
I still think that it might be that layout. We're just not manually removing it in the write place? cause it does show up in the stack trace of the error
b
I'd clear it before exiting the handler
Also, are you setting it to an empty string or deleting the key?
And what was it before the renderer call?
z
we tried using struct.delete after the service call that uses the renderer but inside the handler still