@yariplus said in Noob Plugin question: Alterin error message on filter hook.:
@jarey no problem.
I fixed some typos in my code above, and tested it on my forum, and verified it works. Let me know if you run into any other errors.
I'm feeling pretty stupic, but got to ask again in order to solve my doubts.
As i said, now i'm only trying to acces a topic, execute a dummy assigment of an url in the privilege object, and then redirect to that url.
As you pointed out, i try to do exactly that binding my dummy functions to the hooks filter:privileges.topics.get for the url assignment on the privilege object and filter:topic.build for the redirection.
Well i keep getting the following error on the browser what makes the page stay with the laoding animation forever:
nodebb.min.js?16247918-a870-4cf5-8ec8-e783ea5bf570:21353 Uncaught TypeError: Cannot read property 'name' of undefined
My dummy code is as follows: (pretty reading on my updated dummy repo https://github.com/jarey/nodebb-plugin-tagstitle )
// filter:privileges.topics.get
tagsTitle.privilegesTopicsGet = function(privileges, callback) {
var thing = true;
//Dummy asignment for the redirect url.
if (thing){
privileges.redirectUrl = 'http://localhost:4567/users';
}
callback(null, privileges);
};
// filter:topic.build
tagsTitle.topicBuild = function (data, callback) {
if (data.templateData.privileges.redirectUrl) {
//Execute redirect to the new page.
data.res.redirect(data.templateData.privileges.redirectUrl);
//data.template.name= 'topic-error';
}else{
callback(null, data);
}
};
I really don't know what I'm doing wrong; i've tried populating the data.template.name attribute, but if i try to make the redirect using that, i get the error of the closed sockets again on mongo.
Any pice of advice is really appreciated.
Thanks again.