I am using Facebook marketing/graph api v2.8. I have read exception handling from here https://developers.facebook.com/docs/php/FacebookRequestException/5.0.0, I am using following code for exception handling.
try {
} catch (Facebook\Exceptions\FacebookResponseException $e) {
return $e->getMessage();
} catch (Facebook\Exceptions\FacebookAuthenticationException $e) {
return $e->getMessage();
} catch (Facebook\Exceptions\FacebookAuthorizationException $e) {
return $e->getMessage();
} catch (Facebook\Exceptions\FacebookClientException $e) {
return $e->getMessage();
} catch (Facebook\Exceptions\FacebookOtherException $e) {
return $e->getMessage();
} catch (Facebook\Exceptions\FacebookServerException $e) {
return $e->getMessage();
} catch (Facebook\Exceptions\FacebookThrottleException $e) {
return $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
return $e->getMessage();
} catch(Exception $e) {
return "error";
}
But still I am getting following AuthorizationException
Uncaught exception, operation failedexception 'FacebookAds\Http\Exception\AuthorizationException' with message '(#2663) Terms of service has not been accepted. To accept, go to https://www.facebook.com/customaudiences/app/tos?act=
I tried to include
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Exceptions\FacebookAuthenticationException;
use Facebook\Exceptions\FacebookAuthorizationException;
use Facebook\Exceptions\FacebookClientException;
use Facebook\Exceptions\FacebookOtherException;
use Facebook\Exceptions\FacebookServerException;
use Facebook\Exceptions\FacebookThrottleException;
use Facebook\Exceptions\FacebookSDKException;
But still no gain.
Actually I want to cover maximum errors so that can show to users in a user friendly way so anyone can tell what I am missing or what is the perfect way for exception handling in facebook marketing api?
The reason is you are mixing two SDKs in your code. One is the general Facebook SDK and another is Facebook Marketing API SDK (https://github.com/facebook/facebook-php-ads-sdk)
Those exceptions start with Facebook/ are from Facebook SDK and those starting from FacebookAds are from Marketing API SDK.
I completely understand this is not ideal for developers. But you can also see the reason we have a separate SDK for Marketing API is because our Ads data model are too complicated and we need a more strong typed SDK to help developer to do the integration. And due to lots of reason it cannot be build on top of the general Facebook SDK.
So for now, you will have too look at both documentations for Marketing API/SDK and the general Facebook SDK. We will get your feedback and see if we have opportunity to improve it.
Related
In my app I have many of queries and mutations like mentioned below:
query name1($token: String!){
session(authToken: $token) {
user {
id
}
}
}
mutation name2($token: String!){
session(authToken: $token) {
getSomething()
}
}
If there are some problems with session on server side I get from server a response - session: null and it is OK. Because of many queries and many mutation how can I catch this specific response ({session: null}) and fire some method (in my case logout and destroy token in localstorage). I need some general solution (maybe some afterware or sth like that) instead of catching that response in every query and mutation.
I can think of two solutions:
1- Have your server throw an Error instead of null and catch that error in your client using apollo-link-error https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-error
2- Write a custom Apollo Client that looks for the specific value ({session: null}). For that, I recommend looking at the source code of any of the available Apollo Links or check out this tutorial https://dev-blog.apollodata.com/creating-a-data-component-with-apollo-link-f0719d8193ee
I have a MVC app where I am trying to capture all the incoming requests in a ActionFilter. Here is the logging code. I am trying to log in a fire and forget model.
My issue is if I execute this code synchronously by taking out the Task.Run Elmah does send out an email. But for the code shown below I can see the error getting logged to the InMemory logger in elmah.axd but no emails.
public void Log(HttpContextBase context)
{
Task.Run(() =>
{
try
{
throw new NotImplementedException(); //simulating an error condition
using (var s = _documentStore.OpenSession())
{
s.Store(GetDataToLog(context));
s.SaveChanges();
}
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex);
}
});
}
Got this answer from Atif Aziz (ELMAH Lead contributor) on the ELMAH google group:
When you use Task.Run, the HttpContext is not transferred to the thread pool thread on which your action will execute. When ErrorSignal.FromCurrentContext is called from within your action, my guess is that it's probably failing with another exception because there is no current context. That exception is lying with the Task. If you're on .NET 4, you're lucky because you'll see the ASP.NET app crash eventually (but possibly much after the fact) when the GC will kick in and collect the Task and its exception will go “unobserved”. If you're on .NET 4.5, the policy has been changed and the exception will simply get lost. Either way, your observation will be that mailing is not working. In fact, logging won't work either unless you use Elmah.ErrorLog.GetDefault(null).Log(new Error(ex)), where a null context is allowed. But that call only logs the error but does not do any mailing. ELMAH's modules are connected to the ASP.NET context. If you detach from that context by forking to another thread, then you cannot rely on ELMAH's modules. You can only use Elmah.ErrorLog.GetDefault(null).Log(new Error(ex)) reliably to log an error.
I have an app that sends out notifications to users (timeline cards) and some of the users are reporting that they are receiving the same timeline card multiple times (up to 5 times in one instance). Has anyone encountered this? My app is utilizing the Mirror API.
I've reviewed my log files and only see the timeline card produced once. I'm at a loss. I'll provide any code or logs that are needed. My app is written in Python.
Thanks!
This shouldn't be happening. If you're seeing it persist, file a bug in the official issue tracker.
If you do file a bug, there's one thing that might help Google find the root cause. Do a timeline.list on a user who reports the multiple notifications. Does the API show multiple cards? If so, include the JSON representation of them (including the ID)
The specific code to do this list depends on the language you're developing in. Here's an example of how to do it in Java:
public static List<TimelineItem> retrieveAllTimelineItems(Mirror service) {
List<TimelineItem> result = new ArrayList<TimelineItem>();
try {
Timeline.List request = service.timeline().list();
do {
TimelineListResponse timelineItems = request.execute();
if (timelineItems.getItems() != null && timelineItems.getItems().length() > 0) {
result.addAll(timelineItems.getItems());
request.setPageToken(timelineItems.getNextPageToken());
} else {
break;
}
} while (request.getPageToken() != null && request.getPageToken().length() > 0);
} catch (IOException e) {
System.err.println("An error occurred: " + e);
return null;
}
return result;
}
Can anyone show me how to handle exceptions when using the .NET SDK for AWS SES?
The implementation of IAsyncResult that is returned has the Exception on it, but its internal.
Is there an alternative method for accessing this, or do I need to reflect it :(
amazonSimpleEmailServiceClient.BeginSendEmail(sendEmailRequest, ar => {
var result = ar as AsyncResult;
// result has .Exception, but its internal :(
}, null);
Thanks
The standard approach with Begin*/End* methods in the .NET AWS SDK (and .NET overall, as discussed in a bit of detail here) is to call the corresponding End* method.
amazonSimpleEmailServiceClient.BeginSendEmail(sendEmailRequest, ar =>
{
try
{
amazonSimpleEmailServiceClient.EndSendEmail(ar);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}, null);
Can I just do this below? Or is there a more proper way to do it ?
ServiceReferenceSLHS.HighScoreWSClient client = new ServiceReferenceSLHS.HighScoreWSClient();
client.GetHighScoresCompleted += new EventHandler<ServiceReferenceSLHS.GetHighScoresCompletedEventArgs>(client_GetHighScoresCompleted);
try
{
client.GetHighScoresAsync();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
Your code will only capture errors generated when calling the method GetHighScoresAsync. It's normally very unlikely that you'll have sure exceptions.
It's much more likley that you want to capture exceptions in the callback function (client_GetHighScoresCompleted).
Check the EventArgs there for errors.