When does RTCDataChannel.onerror is called? - error-handling

I'm making a program to transmit data with WebRTC. I want to implement RTCDataChannel.onerror because I want to deal with an error event.
I read the document below, but the explanation is ambiguous. I want more specific information about the error. I want to know what happens when this method is called.
https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/onerror

The RTCDataChannel.onerror is an attribute which you should set to a function. You should set the value of RTCDataChannel.onerror to a function which handles the error. For example:
RTCDataChannel.onerror = function(error) {
// handle the error
alert("Uh oh, there is a problem. " + error);
}

Related

Mobx : changing (observed) observable values without using an action is not allowed (asynchronus handler)

we know all this problem, and know how to solve it.
But I have an stranger Error in this context where I could use a good hint:
this.getData(id)
.then((response) => {
this.root.basic.selected.num = response.data.number; // number
this.root.basic.selected.date = response.data.date; // Date
this.root.basic.selected.text = response.data.text; // String. <- There is the error
}
})
The selected Object is bound by the "makeAutoObserveable()" Nothing special here. But a lot of code to push it all here.
Why this error happens only on the .text setter not on the others?
Is this a possible known behavior?
I solved it with "runInAction()" but I would like to understand the reason.
Kind Regards
Gregor

Proper way to send Web API response

I read somewhere that TRY CATCH is not recommended in Web API methods.
I'm making the following call into a method and if all goes well, I want to return an Employee object along with Status 200 but if something goes wrong e.g. database call fails, etc. I want to return status 500. What's the right way to handle that code?
[HttpPost]
public async Task<IHttpActionResult> PostNewEmployeeAsync(Employee emp)
{
var newEmployee = await RegisterEmployee(emp);
return Ok(emp);
// What if I had a database error in RegisterEmployee method. How do I detect the error and send InternalServerError()
}
private async Task<Employee> RegisterEmployee(Employee emp)
{
// Call DB to register new employee, then return Employee object
}
Your code should return the error code that matches the case that you have, for example if your code couldn't find the required resource in the database return NotFound,
but if you code raises an exception, avoid wrapping your code by try/catch block and instead the exception should bubble up to the level that you can handle it globally, to do this you have many options like :
1- Implement an ExceptionFilter where you can handle all the unhandled exceptions raised in your controllers (this doesn't include any exception happens before the controllers in the pipeline).
See this for more details about ExceptionFilterAttribute.
2- If you are using Web API 2, you can implement the interface IExceptionHandler where you can handle all the exception happens anywhere in the pipeline and there you can return the errors you want.
See this for more details about Global Exception Handling in Web API 2.
Hope that helps.
You don't want to avoid try/catch entirely, you just need to be really careful about it. Wrap your code in a try block, and catch the exception you're expecting. Inside the catch, return the error response.

ReactiveCocoa binding "networkActivityIndicator" Crushes

I have this code:
RAC(self.viewModel , password) = self.signupCell.passwordTextField.rac_textSignal;
RAC(self.viewModel , userName) = self.signupCell.usernameTextField.rac_textSignal;
RAC([UIApplication sharedApplication], networkActivityIndicatorVisible) = self.viewModel.executeRegister.executing;
At my LogIn page.
At first is runs perfect, But it user Logout and gets to the register page once again, the app crushes at the line:
RAC([UIApplication sharedApplication], networkActivityIndicatorVisible) = self.viewModel.executeRegister.executing;
With Error:
'Signal name: is already bound to key path "networkActivityIndicatorVisible" on object , adding signal name: is undefined behavior'
I'm guessing it has something to do with subscribing to UIApplication events. But I'm not sure what else can i do beside sending subscriber completed as so:
[subscriber sendCompleted]
Any one had the same problem?
thanks.
EDIT
With the help of #erikprice and #powerj1984 I found a solution:
RAC([UIApplication sharedApplication], networkActivityIndicatorVisible) = [self.viewModel.executeRegister.executing takeUntilBlock:^BOOL(id x) {
return _viewShowing;
}];
The "_viewShowing" veritable is setted to YES on ViewWillAppear, And to NO on ViewWillDisapear.
This is not the best coding.. So if anyone has a better option i would be happy to use it.
Thanks.
That error message means that you're trying to call RAC(UIApplication.sharedApplication, networkActivityIndicatorVisible) more than once. Make sure you only make that call on that specific property of that specific object one time, ever. (Or at least until such time as you dispose of the subscription, as #powerj1984 suggests.)

sharedObject does not save my data.

static private function ifonEnternameFrame():Void
{
so.data.name = _root.getName.text;
//trace(so.data.name);
_root.nameBtn.onPress = function ()
{
_root.gotoAndStop(2);
}
}
When you start the application this code will save your name.
But when you then go to another function then it says that it's undefined.
trace(so.data.name);
I traced this when I was on the next frame and it couldn't find the previous name.
Please help.
Flushing the shared object data is necessary to get those variables.
Use the flush function of shared object.
Your problem doesn't come from SharedObject. The origin of your error message is that your textField getName is incorrectly named in your code.
If you trace _root.getName.text in your function ifonEnternameFrame you shall have the same error message:
trace(_root.getName.text); // undefined

accessing javascript function arguments

Documentation for JQAjaxSetup>>onError: says:
onError: anObject
"A function to be called if the request fails. The function is passed three
arguments: The XMLHttpRequest object, a string describing the type of error that occurred
and an optional exception object, if one occurred. Possible values for the second argument
(besides null) are 'timeout', 'error', 'notmodified' and 'parsererror'."
I'd like to display the error message using something like
anAjax onError: ((html jQuery id: someId) before: (MyInstanceOfWAPainter error: 'An error message'));
How do I do that? Possibly doing it all on the client side.
Because the error happens client-side and you probably have a failing connection in such an event, you need to generate the complete javascript code that will display the error (i.e. without rendering callbacks to Seaside).
The snippet below will generate a JS function with two arguments. The body of the function is the jQuery expression that will put the error message (inside the _error variable) right before the html dom element with id someId.
anAjax
onError: (((html jQuery id: someId) before: (JSStream on: '_error'))
asFunction: #('_XMLHttpRequest' '_error'));
Personally, I would not use Seaside's JS-generation functionality here if the id in someId is not dynamically generated. If it's dynamically generated from within Seaside, the first snippet might still be easier.
anAjax onError: (JSStream on: 'function(_XMLHttpRequest,_error){
$(''#someId'').before(_error)})
According to documentation you can do below to show the error:
onError:function(_XMLHttpRequest, _error) {
alert(_error);
}
this basic idea would be:
jQuery ajax onError: (self javascript alert: 'error')
see JQAjaxTest>>testOnError.