SignalR Catching Exceptions - signalr

I have a simple login hub which clients may submit a username. The hub throws a exception if the username is already in use. On the client I am trying to handle the exception and read the message. However the message I am reading is 'One or more errors has occurred'.
try
{
await Client.SignIn(user);
UserName = SignInInput;
}
catch (Exception ex)
{ //One or more errors has occurred }
I asked this message on the SignalR github and I received the response:
You need to unwrap the errors. We provide this functionality via the SignalRError object. Here's a sample of how you can unwrap an Exception e.
using (var error = e.GetError())
{
Console.Error.WriteLine(error);
}
In the future please ask questions on sites such as Stackoverflow or chat with us in http://jabbr.net/#/rooms/signalr.
Now I'm looking through my Object Browser and I can't seem to find any such method or class anywhere.

It's an extension method, in SignalR.Client.ErrorExtensions.

Related

How do I get a more accurate error message from the http.dart library when the server is not available?

I'm using Flutter Web and therefore the http.dart library, not the dart:io library.
I make a post request to my webserver and I would like to get a good error message when the server isn't running at all.
I catch the ClientException, but with .toString() the only thing I get is "XMLHttpRequest error.".
The response object is null, so I don't get any more detail from there.
Is it maybe related to the limited functionality of the library, because it is limited by the web browser?
I would want something like "Server cannot be reached." or even more details.
http.Response resp;
try {
resp = await client.post(host, headers: {"Content-Type": "application/json"}, body: "bla");
} on http.ClientException catch (err, stacktrace) {
print(err.toString());
print(stacktrace.toString());
}
Thanks for your help!

Errors thrown on Meteor server methods dont log original stack trace

Since upgrading to meteor 1.8.0.2 from 1.6.x I've noticed that any method call that results in an error is printed on the server console as:
Exception while invoking method 'login' [object Object]
Exception while invoking method 'customMethodByMe' [object Object]
This happens both on development on my mac and deployed on Galaxy.
Before, the whole stack trace was printed, but this Object object logging doesnt help me figure out the actual problem. My solution so far has been to wrap method implementation in a try catch statement that logs the original exception and rethrows it for the client to know.
Meteor.methods({
'customMethodByMe'() {
try {
return customMethodByMeImpl();
} catch (e) {
console.log(e)
throw e;
}
}
});
In this case, since the error is on the login method which is in a package, I cannot update it to print the real problem. On the client, all I get on any error is that there was a 500 error on the server, so no root cause either.
{"isClientSafe":true,"error":500,"reason":"Internal server error","message":"Internal server error [500]","errorType":"Meteor.Error"}
Any ideas on how to temporarly solve this? I've been searching for a server level error handler but so far have found nothing.
thanks
I did not get to experience this directly, but when I need to print an object, I usually use JSON.stringfy.
Meteor.methods({
'customMethodByMe'() {
try {
return customMethodByMeImpl();
} catch (e) {
console.log(JSON.stringify(e));
throw e;
}
}
});
This should resolve so that you can at least read the error log.

Can't get user information after login successfully in WSO2 Identity server

After login successfully into WSO IS with service URL (https://localhost:9443/services/")
I tried to get User Information as below :
try {
UserRealm realm = WSRealmBuilder.createWSRealm(serviceURL, authCookie, configCtx);
UserStoreManager storeManager = realm.getUserStoreManager();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But I had exception relating to this as below image. I can't get any info.
I tried and found out that the main error is I can't create ConfixContext with the following code :
configCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
I also read about ConfigContext in the below link and tried with other methods in this link but I can't create configContext.
http://axis.apache.org/axis2/java/core/apidocs/org/apache/axis2/context/ConfigurationContextFactory.html
I appreciate your help in this case.
Thanks
The problem is your runtime doesnt have org.wso2.carbon.user.api.UserStoreException class. Therefore you can't identify the real exception.
For now, just use Exception e instead, and see if you can log the real exception.

In Meteor, what is difference between this.error and throw new Meteor.Error in Meteor.publish?

In Meteor.publish, what is a difference between using this.error and simply throwing an Meteor.Error?
this.error is only available inside the publish method. Per the docs:
Stops this client's subscription, triggering a call on the client to the onError callback passed to Meteor.subscribe, if any. If error is not a Meteor.Error, it will be mapped to Meteor.Error(500, "Internal server error").
Throwing a Meteor.Error would not stop the client's subscription, it would just terminate execution and raise the exception. So if you want to ensure Meteor will clean up after you and allow you to handle the error on the client when something unexpected happens, it's recommended to use this.error rather than throwing your own inside the publish method.
It seems they are the same. In the source code:
try {
var res = self._handler.apply(self, EJSON.clone(self._params));
} catch (e) {
self.error(e);
return;
}
So if there is an exception thrown, error is called anyway. error also stops the subscription.

Sending SMS using Twilio from my website in asp.net

I am trying to send SMS from twilio account. Here is my code.
try
{
string ACCOUNT_SID = ConfigurationManager.AppSettings["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"];
string AUTH_TOKEN = ConfigurationManager.AppSettings["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"];
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
client.SendSmsMessage("+1XXXXXXXXXX", "+1XXXXXXXXXXX", "Hi");
Label1.Text = "Sent Successfully";
}
catch (Exception ex)
{
Label1.Text = "Error:"+ex.Message;
}
Running on my server, I am receiving message "Sent Successfully" but not receiving message on my phone.
I have changed the original numbers with "XXXXX".Also I have added packages for Twilio.
Please let me know if can.
Twilio evangelist here.
You might be getting an error back from the Twilio REST API when you make the call to SendSmsMessage. You can check if this is happening by grabbing the value returned from the method and seeing if the RestException property is null or not:
var result = client.SendSmsMessage("+1xxxxxxxxxx", "+1xxxxxxxxxx", "Hi");
if (result.RestException!=null)
{
//An error occured
Console.Writeline(result.RestException.Message);
}
Another option would be to use a tool like Fiddler to watch the actual HTTP request/response as it happens and see if any errors are happening.
Hope that helps.

Resources