Internationalization of error codes with tap-i18n - meteor

I'm currently developping a multi languages application using the tap-i18n package. I wonder how I can translate errors.
I can grab the code and then display a custom message that I would have written to the translation file before.
But I saw on this post there is a better way of doing this with another i18n package.
Does anyone know if there is way of doing something like with tap-i18n ?
EDIT : For now I'm doing something like this :
Meteor.call('createNewUser', newUser, function (error, ret)
{
if (!error)
displayError(TAPi18n.__('success'), TAPi18n.__('new_user_success'), TAPi18n.__('ok'), "btn-success btn-lg", "success-popup");
else
{
switch (error.error)
{
case 403:
displayError(TAPi18n.__('danger'), TAPi18n.__('new_user_already_exist'), TAPi18n.__('ok'), "btn-danger btn-lg", "danger-popup");
break;
default:
displayError(TAPi18n.__('danger'), TAPi18n.__('new_user_error'), TAPi18n.__('ok'), "btn-danger btn-lg", "danger-popup");
break;
}
}
});

My answer might be a bit off-topic, but do you mean application errors? If so, you shouldn't really return that to the users, as this could constitute a security flaw, giving them too much information.
From OWASP: https://www.owasp.org/index.php/Error_Handling
Thus, you might want to handle the errors, and give the users exactly what you want them to know.
Just include the error messages in your translation, and proceed as with normal strings to translate.
I hope this is of some help :).
EDIT:
I understand now what you mean. As far as I know, there's no such option, as there is with just-i18n. As a suggestion for unbloating the code a bit, you could use a helper function such as:
function t(keyToTranslate){
return TAPi18n.__(keyToTranslate)
}
And in the code:
displayError(t('danger'), t('new_user_already_exist'), t('ok'), "btn-danger btn-lg", "danger-popup");
A bit naive suggestion, but there's no functionality to map the errors in this package, as far as I know. The way you're handling it seems correct to me.

Related

Sulu: How to get the exact location of template errors in preview?

When I develop templates in Sulu 1.6 and an error occurs, where can I find the full error or exact error location? Is there some kind of special log or do I need to change the default location?
The corresponding /admin/websocket/admin response contains only this (basically the same information):
{
"handler":"sulu_preview.preview",
"message":{
"code":9903,
"message":"Unclosed \"block\".",
"type":"Sulu\\Bundle\\PreviewBundle\\Preview\\Exception\\TwigException"
},
"options":[],
"error":true
}
Currently I only see messages like this:
It would be also helpful to know, where the catch block for this is, in case it is not jet implemented.
Thx a lot!
So it turned out, that there is no logging enabled, and because the PreviewRendere throws a new Exception, the original information is pretty much lost. It can be added in this way: https://github.com/sulu/sulu/pull/4363
Best wishes
Andreas

How to give Httpful a String with double quotes in it?

The idea is to send terms like bob & \\apples to a server. I get this error:
Fatal error: Maximum execution time of 30 seconds exceeded
public function index($request, $response)
{
$uri = 'http://example.org/folder?key=["bob", "\\apples"];
$content = \Httpful\Request::get($uri)->send();
return $content;
}
As user RWC pointed out, it seems to be the library which causes this error.
The mysterious thing is, that it works with only one term (?key="bob") but with two it doesn't. When I put the URL into my browser, I get back the proper results (JSON response) with one and with two terms. So at the end it works but Httpful does something I don't know of yet.
The question you are asking is very specific for the libary you are using, Httpful, and is not a pure PHP question.
This is a valid URL:
https://www.google.com/search?q=\
and so 'http://server/search?key=\' is a valid URL.
If the following command does not work
Request::get($uri)->send()
you have to blame the library (Httpful). You provided a valid URL, so in my opinion if the libary was well written, it should work.
So you have to do something to make it work. What? For that you have to read the documentation of the library.
Good to hear that you find a solution, but is has nothing to do with normal PHP.
ini_set('max_execution_time', 500);
in your script,place this one on the top,its increase the execution time of your code.

Visually testing unusual code paths in ASP.NET WebForms Website

I have a large complex ASP.net WebForm website that I'm working on a visual redesign and am trying to think of good ways to exercise all the code paths in the website so I can see how things look with the redesign.
For example lets say I have a message that only gets displayed if there is an error which rarely happens. Here is an example of what my code might look like:
if (someErrorCondition) {
someControl.Visible = true;
} else {
someOtherControl.Visible = true;
}
This might not be a good way of doing things, but this is a good example of my existing code base I have to work with.
Let us assume for the sake of simplicity that I already have a way of testing one part of the if. The problem is exercising the other part without going through a lot of trouble to setup my environment to create an error.
One idea I had was to extract someErrorCondition into a method and in that method check for some session or request key to see if I want to fake a failure. Maybe wrap it in an #if DEBUG block so that it won't be compiled for production.
Any other ideas for how I might go about testing unusual code blocks on an ASP.net website so I can make sure nothing got left out in the redesign?
I believe the best solution is always the most simple. Since you obviously have access to the code, do a search for the Visible property for each form element within Visual Studio and set each one to true to see how it looks. Once you make the design change then un-comment the original code.
Example:
if (someErrorCondition) {
someControl.Visible = true;
} else {
someOtherControl.Visible = true;
}
TO
/* if (someErrorCondition) {
someControl.Visible = true;
} else {
someOtherControl.Visible = true;
}*/ someControl.Visible = true;
This is not good for testing proper behavior of the form, but will let you see how each element looks for visual design purposes.

generic identifier

as I probably do not describe the problem in the right terms, I was not able to get an answer with google. Please excuse!
In the following code, I would like to replace 'hardcoded' identifier COMMENT with the variable editedField. How to do that?
var editedField:String = event.dataField;
if (model.multipleProcessingData[i][editedInformationProductNO].COMMENT != null{
...
}
Make sure you wrap this in try/catch block for NPE's, as you'll eventually find one with this many [] accessors.
A better, more OOP, would be to have an accessor function on your model that you can pass your data to:
model.getEditedField(i, editedInformatioNProductNO, editedField)
This will make it easier to troubleshoot and add good error messages to your app if things don't turn out like you expected.
var editedField:String = event.dataField;
if (model.multipleProcessingData[i][editedInformationProductNO][editedField] != null{
...
}

WatiN - getting past the certificate error page

Anyone know how to use CertificateWarningHandler in WatiN?
I've got as far as...
IE ie = new IE("https://mysite.aspx");
CertificateWarningHandler cwh = new CertificateWarningHandler(CertificateWarningHandler.ButtonsEnum.Yes);
cwh.HandleDialog(new Window(ie.hWnd));
... which does precisely nothing.
On a more general note, how on earth do you people manage to use this tool? The documentation is nearly useless, and there doesn't seem to be any decent resource online. I must be missing something because it's taken me about half an hour to write 3 lines of code that don't even work.
I'm using something similar to what Saar is using and it works fine (my tests are cross-browser).
//Override security warning in browser
{
if (Browser.Link(Find.ById("overridelink")).Exists)
{
Browser.Link(Find.ById("overridelink")).Click();
Browser.WaitForComplete();
}
else
{
Browser.WaitForComplete();
} //end else
}
I'm not a developer, and I've found that there's plenty of information out there on WatiN and others post code samples and the like that are really helpful. Google is one of my best friends when it comes to finding WatiN help. You'll get the hang of it.
have you tried following already?
ie.DialogWatcher.Add(cwh);
or just
ie.DialogWatcher.Add(new CertificateWarningHandler());
Update: After comment.
Actually this works for me.
further may be following will help
Browser browser = ie;
if (browser.Links.Exists("overridelink"))
{
browser.Link("overridelink").Click();
}

Resources