I would like to control and embed my send() calls in a try/except, but I'm not sure of what errors it can produce.
Looking around the SDK, it seems like MailServiceError is the one, but not sure since I don't know how to test an error like that.
Can anyone confirm this?
Here are the exceptions that can be thrown by a call to send(): https://developers.google.com/appengine/docs/python/mail/exceptions
Here's an example of how you could catch these:
from google3.apphosting.api import mail
# other code to create 'message' here
try:
message.send()
except mail.InvalidSender, e:
# Do something special for an invalid sender error
pass
except mail.Error, e:
# This will catch all the other exceptions in the doc above.
pass
Related
I would like to redirect messages from g_warning() and similar functions from gtkbuilder.c such as the famous:
(main.exe:39280): Gtk-WARNING **: 01:34:48.787: Could not find signal
ha ndler 'on_window_realize'. Did you compile with -rdynamic?
using g_log_set_handler(). It expects the domain name as the first parameter, which is what I can't seem to find. If G_LOG_DOMAIN is not defined in the source then it defaults to NULL in which case I won't be able to use g_log_set_handler() to redirect it.
What is the log domain name for it or alternatively - how can I redirect those messages after all (I am redirecting them to a GtkTextBuffer)?
GTK is using structured logging, which means the g_log_set_handler() won’t work.
g_log_set_writer_func() should be used instead to catch every structured log and parse the given GLogWriterFunc in the callback.
We have configured REST proxy service that accepts JSON input. If the input is not a well formed JSON OSB is throwing Translation error with HTTP 500 Staus code. Is that possible we can send Customized error message in this scenario
You need to create a global error handler for your pipeline and set the desired error message using a replace action here, followed by a "Reply" action.
Keep in mind that if you try to "read" the original request body in the global error handler, and if the original request was malformed, it will get thrown up to the system error handler and you will get the system error message again.
Here's a sample OSB 12.2.1.1 project you can use to try this: https://github.com/jvsingh/SOATestingWithCitrus/tree/develop/OSB/Samples/ServiceBusApplication1
The accompanying soapui project contains two requests. The malformed request should return this:
(I have only set the response here. You would also need to set the proper content type and decide whether you want to treat this as "success" or "failure" etc. in the reply action)
Try as I might I cannot seem to make quickfixj take a dictionary - or indeed give any sign its registered the dictionary at all, I have no choice but to use the dictionary and it is not something I have control over. I've tried various uses of the DataDictionary property which is in the documentation and in quickfixJEndpoint class, but I really expect to set it on the endpoint, but dont seem to have any way to do that
I have an accpetor A
and an initiator B
I want to send a message from acceptor to intitiator via A->B
send an ack back from initiator to accpetor via B->A
The last place it 'works' is just before sending to the fix endpoint A->B
The initiator and acceptor connect, handshake and log-on with no problem, then the acceptor constructs its non-standard fix-message and send it, right before it sends is the last time before an exception occurs.
It includes a tag '15' which is causing a problem because the type it is being used on does not normally include 15, but with the DataDictionary it does - but it isn't loading the dictionary and quickfixj is throwing an invalidField exception because it doesn't like tag 15 being there since its not on the base-type.
I set on the exchange everything I can to make it acknowledge the datadictionary, everywhere I can
on route
in process {
TradeCaptureReport fix = new TradeCaptureReport();
fix.setString( 15, "my value" );
....
exchange.setProperty( QuickfixJEndpoint.DATA_DICTIONARY_KEY, "mydictionary.xml" )
exchange.getOut().setProperty( QuickfixJEndpoint.DATA_DICTIONARY_KEY, "mydictionary.xml" )
exchange.getOut().setBody( fix );
}
quickfix.FieldException: Tag not defined for this message type,
B->A , error> (Reject sent for Message 2: Tag not defined for this message type:15)
It never reaches the code inside the acceptor which would normally receive A->B and return B->A as a response, so although it report B->A and think that is incorrect
I hope I've given enough info here. scratching my brain for how to get quickfixj to pick up this dictionary.
Oh, the resource definietly exists, although nothing indicates it ever even tries to look for it, it definitely doesn't seem to be hitting anyything 'in the code' to indicate that it has done anything to look for a DataDictionary.
Any ideas how I can set a DataDictionary
The last place it 'works' is at A->B, I define the fix-message but it craps-out when I send it. the error message is reported on B->A - which is a bit wierd, then again, there's a LOT of stack trace, it definietly doesn't get into the code of the reciever
I solved myself by avoiding camel's mechanism to do DataDictionary, which as of 2.11.2 doesn't seem to work and just set the dictionary in the settings file. Works.
All,
Is there a way to error out/exit execution out of a handler? For instance, if the incoming request doesn't contain the correct headers we want to send a 400 and exit/close the connection. However, whenever we use self.error(400) or self.response.set_status(400) any other code after it executes anyway So, for example:
class MyPastaHandler(webapp2.Handler):
def get():
if not self.request.headers.get('My-Custom-Header'):
self.error(400)
...
[more code]
self.response.out.write('{"success": "true"}')
When I submit a request w/o the said custom header, I get back a 400, but I also get the success json in the body of the response, which tells me that self.error(400) doesn't stop execution and neither does self.response.set_status(400).
So, the question is, is it possible to literally error out of a handler?
As it turns out, there is a simple way to exit after a 400 (or any custom error). As described by TheFluff in the AppEngine IRC channel, a simple, old-fashioned empty return after the self.error(400) will do the trick.
In webapp2 abort() is a shortcut to raise a HTTP exception: http://webapp-improved.appspot.com/guide/exceptions.html#abort
I do the following:
try:
result = urlfetch.fetch(url=some_url,
...
except DownloadError:
self.response.out.write('DownloadError')
logging.error('DownloadError')
except Error:
self.response.out.write('Error')
logging.error('Error')
Is there any way to get some more detailed description on what happened?
You should use logging.exception to add the Exception to the ERROR logging message:
try:
result = urlfetch.fetch(url=some_url,
...
except DownloadError, exception:
self.response.out.write('Oops, DownloadError: %s' % exception)
logging.exception('DownloadError')
except Error:
self.response.out.write('Oops, Error')
logging.exception('Error')
In short, no. A download error is usually a timeout in our experience - something on the back end taking too long to respond (first byte). If it is receiving data, it looks like GAE will wait and throw a Deadline exception instead after your 10 seconds is up.
Does it ever succeed? Your choices on how to deal with d/l exceptions will vary depending on the back-end.
If you're taking the simplistic route and just retrying, beware of quotas and limiters - chances are your requests are indeed reaching the other system, and just aren't coming back in time. Very easy to blow past limiters this way.
J