In play framework, every time you get an Internal Server Error (500) in production mode, the browser shows a web page with
Oops, an error occured, This exception has been logged with id XXXX
I would like to customize the error message (or at least translate it to spanish), keeping the error id that makes it easier to look for in the application log.
I've tried to configure an error page in the Global settings in JAVA like this:
public Promise<Result> onError(RequestHeader request, Throwable t) {
return Promise.<Result>pure(internalServerError(
views.html.error.render(t)
));
}
Where I've a view named error.scala.html.
It is not working right now, it does not show any errors, just ignores it. Also with this alternative, I don't know how to display the error id.
I appreciate any suggestions, thanks a lot.
Is your Global class in the root package? That's a quite common mistake and also the reason why it is ignored.
Related
I want to close my Android application with a method, but it should be shown a custom message (which I define for myself).
everything I found yet was "How to close my application" and I got more than 10 ways to close my application but I haven't found a way to set a custom message.
At the moment if my app crashes something like this appears:
[APPNAME] has been stopped
I want something like this
Congratulations! You found a bug, please submit it.
Is there even a way to do that? All methods I found just closed all activities or just forced an unresolveable error.
I don't think you need some code from me, but if you do, tell me.
(Language should be java and javascript/jQuery should be avoided)
You could try making a static stop method:
public static void stop(String message) {
Log.d(message);
System.exit(0);
}
I have the below constructor for my customized exception
public CoException(String errorMessage) {
super(errorMessage);
CoDebugger.debugException(errorMessage, this);
}
A static code analyzer tool (fortify) identifies vulnerability issue in this portion of code.
The message given by fortify is
"The method CoException() in CoException.java mishandles confidential information, which can compromise user privacy and is often illegal."
Please let me know where is the issue and how to fix that.
The tool makes a data flow analysis:
Incoming: String errorMessage - What error message could contain interesting information for an attacker? Let me think. Login failed: user=admin pwd=123456 would certainly be something that should be kept internally.
Outgoing: super(errorMessage); and CoDebugger.debugException(errorMessage, this); - What does the debugException method? Does it show the error message directly to the user? That should not happen. Or is the error message written to a log file which under certain conditions (e. g. by an incorrect .htaccess configuration) can be accessed by the user. That should also not happen, of course.
I am using Twitter4J 2.2.5 (latest, tried other versions). And can no longer get direct messages to work at all. The same code used to work a while ago. I assume Twitter changed something.
I'm using
Twitter.getDirectMessages()
and it gives the error below. No idea why, I can see the direct messages for the account if I login, but always get this error. The limit error makes no sense, as the account is no where near the limit.
Other API work, like followers/fried/status/etc.
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (http://support.twitter.com/forums/10711/entries/15364).
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=00919618 or
http://www.google.co.jp/search?q=332bf6ca
TwitterException{exceptionCode=[00919618-332bf6ca], statusCode=403, retryAfter=0, rateLimitStatus=RateLimitStatusJSONImpl{remainingHits=107, hourlyLimit=350, resetTimeInSeconds=1328297, secondsUntilReset=1116, resetTime=Fri Feb 03 14:39:45 EST 2012}, version=2.2.2}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:93)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1721)
at twitter4j.TwitterImpl.getDirectMessages(TwitterImpl.java:874)
at org.pandora.sense.twitter.TwitterDirectMessaging.checkDirectMessages(TwitterDirectMessaging.java:44)
at org.pandora.sense.twitter.TwitterDirectMessaging.checkProfile(TwitterDirectMessaging.java:35)
at org.pandora.sense.twitter.Twitter$1.run(Twitter.java:100)
at java.lang.Thread.run(Thread.java:662)
Twitter has some time ago changed the rules for direct messages. An app must be especially authorized by the user to access the direct messages.
Did you make sure this is true for you? You may go to the twitter web site and check for the app.
To get the direct message you should try the below code.It works for me.
getDirectMessages(); gives list of direct messages. We need to put for loop to get text of each message.
List<DirectMessage> messages = twitter.getDirectMessages();
for (DirectMessage message : messages)
{
System.out.println(message.getText());
}
Let me know if you get any error.
If you close the window when using ModalWindows in wicket, you get this message:
"Reloading this page will cause modal window to disappear"
Is there a way to configure this to show OTHER message? (for i18n purposes)
Thanks a lot!!
Manuel
You can dismiss the modal window message by setting the Javascript variable Wicket.Window.unloadConfirmation to false and provide your own handler on window.onbeforeunload.
So you have to set the following Javascript in your pages :
Wicket.Window.unloadConfirmation = false;
window.onbeforeunload=function(){
return I18n("yourI18nKey");
}
That is a browser dependent message and not a wicket message.
I believe Chrome and IE will show the one you pointed out.
Firefox 4 shows "This page is asking you to confirm that you want to leave - data you have entered may not be saved.".
I found out another, quite common way to get that warning when developing a modal view: if you happen to get this confirmation box by accident, it may be an indication of error in your code (Exception on log) and fixing the error also fixes the show of this message.
Good to note is that the confirm box is only an indication of error, not the cause of error itself. The error is elsewhere.
Source: http://ttlnews.blogspot.fi/2010/07/lessons-learned-wicket-spring-hibernate.html
I'm currently using a very simple MVC framework, Bear Bibeault's Front Man, which, for those not familiar, is pretty similar to Spring MVC (in concept at least). One of the issues I'm having is how to handle exceptions properly.
I am currently doing something like this,
try {
//do something
}catch (Exception ex) {
logger.error("Logging error", ex);
Map model = new HashMap();
model.put("error", ex.getLocalizedMessage());
cc.setScopedVariable("model", model);
cc.forwardToView(ERROR_VIEW);
}
Essentially I log the exception and then forward to an error view page.
However this strikes me as not being the right way to do this. It results in a lot of boilerplate code that isn't very DRY.
What is a better way to handle/log exceptions in a web application?
You could do all of your logging inside an error JSP file.
Add this to your web.xml file.
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.jsp</location>
</error-page>
In your jsp file add
<%#page isErrorPage="true" %>
Then you can place your logging inside <% %> and display the error at the same time. All of your logging logic would be in one place and your code would begin to look cleaner.
Instead of using a scriptlet in your JSP file, you could have the location point to a servlet. The servlet could handle all of your processing then forward to the JSP page.
You can also use this technique for different exceptions, so you could process the exceptions differently.
There are varying kinds of exceptions so you should first identify how you want to show them to the user. Forwarding them to a page to display an error may not be the best choice for all of the errors they encounter also keep in mind displaying an error without context can be confusing to some end users.
One way you could handle it would be log all of the none critical errors and have a location on the website where a user could access and review them. (I worked on a project where we had something similar to this. The user could review warnings and errors that wouldn't prevent the application from proceeding.)
You could return them to the page in which the error occurred and populate an error message there. AJAX/Comet could be used to display real time errors to the user without taking them away from the page where the error occurred.