Alternative transport methods: Exception when calling the `failure` callback
See original GitHub issueAdding the following config causes exception Cannot use 'in' operator to search for 'status' in undefined
transport: (params, success, failure) => {
// ...
failure(err); // err object that has a `status` property.
}
I looked into the lib to find where the problem is. It’s exactly here
https://github.com/select2/select2/blob/develop/src/js/select2/data/ajax.js#L85
Where the $request
will always be undefined.
Fix: Allow receiving an error param which we should check against.
function (err) { // <- Receive an error param here
if ('status' in err && (err.status === 0 || err.status === '0')) {
return;
}
// ...
By the way, the docs says:
request.on('failure', failure);
that indicates that the failure
call back accepts parameters.
If this issue and the fix are confirmed, I’m ready for the pull request!
Update: My current workaround:
transport: (params, success, failure) => {
// ...
setTimeout(() => failure(err)); // <-- #1
// ...
return { }; // <-- #2
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
spring feign client exception handling - Stack Overflow
I have some fiegn client to send request other micro service. @FeignClient(name="userservice") public interface UserClient { @RequestMapping( ...
Read more >pika.adapters.twisted_connection — pika 1.2.1 documentation
This means that the connection.channel() method and most of the channel methods return Deferreds instead of taking a callback argument and that ...
Read more >16 Handling Exceptions Using SOAP Faults
This chapter describes how to handle exceptions that occur when a message is being processed using Simple Object Access Protocol (SOAP) faults for...
Read more >AMI in C-Sharp with AsyncResult - Ice 3.7 Beta - ZeroC
For example, the begin_ method throws this exception if you call an operation that has a ... The failure callback always has a...
Read more >LEAF - 1.75.0 - Boost C++ Libraries
O(1) transport of arbitrary error types (independent of call stack depth). Can be used with or without exception handling. Support for multi-thread ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I believe the best solution would be to check if
$request
is not null first, before checking that it has thestatus
property.https://github.com/select2/select2/blob/d0ddab6cebc69e37fe51dfc287c3e3aa37b5cd1d/src/js/select2/data/ajax.js#L85
It’s an optional, undocumented feature of transports where you can have it detect an aborted request. We should be fully supporting the case where a transport doesn’t provide the status property.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.