question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alternative transport methods: Exception when calling the `failure` callback

See original GitHub issue

Adding 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kevin-browncommented, May 1, 2019

I believe the best solution would be to check if $request is not null first, before checking that it has the status 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.

0reactions
stale[bot]commented, Oct 24, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found