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.

Cannot combine handling and passthrough for the same resource

See original GitHub issue

What I need to achieve is to only handle a few of my endpoints with MirageJS (to get certain responses in my e2e tests) and have all other requests pass through to my actual API.

The empty passthrough() function, as suggested in the docs, didn’t work for me at all, but using a function that compares the request.url and request.method with the routes I am handling in MirageJS and returning true for all other requests does the trick. So far, so good.

The issue now is that I need to catch PUT requests to https://api.myapp.com/user in MirageJS, but let GET requests to that same url pass through. This gives me the error this.put() is not a function when the PUT request is sent (not during setup). The GET request, which is sent first, is being passed through as it should. I tried to solve this in several ways, including this.resource('user', { only: ['update'] }) but to no avail.

The only way I got this working is by also handling the GET request with MirageJS – which is not what I want because it means I’d have to copy the exact response from my actual API.

Here is my latest, not working setup:

    window.server = new Server({
        routes() {
            this.urlPrefix = 'https://api.myapp.com';
            this.resource('user');
            this.put('/user', () => console.log('put user with mirage'));
            this.passthrough(request => {
                if (request.url === 'https://api.myapp.com/user' && request.method === 'PUT') {
                    return false;
                }
                return true;
            });
        },
    });

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
samselikoffcommented, Sep 28, 2020

Ok sorry about that - closing for now but feel free to drop more comments if you run into anything! And keep an eye out for new passthrough API hopefully coming soon.

0reactions
alina-beckcommented, Sep 28, 2020

Really sorry, but I don’t have time for that and am not allowed to share the repo I am working on… Wish I could be more helpful! 😕

I’ll just stick with my workaround for now – feel free to close this issue if you want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PassthroughSubject | Apple Developer Documentation
As a concrete implementation of Subject , the PassthroughSubject provides a convenient way to adapt existing imperative code to the Combine model.
Read more >
Error handling in Combine explained with code examples
Error handling in Swift Combine explained by covering operators like mapError, catch, replaceError, assertOnFailure, and how to map to the ...
Read more >
Azure AD Connect: Pass-through Authentication
Key benefits of using Azure AD Pass-through Authentication. Great user experience. Users use the same passwords to sign into both on-premises ...
Read more >
Combine PassthroughSubject and SwiftUI - YouTube
This is the fourth video of the SwiftUI ToDo App series where we are building an ToDoapp from scratch in SwiftUI and then...
Read more >
Why can't I get passthrough subjects to work for combine?
No, cancel() is like dispose() , not disposed(by:) in rx. You should not cancel first, then send things to the subject. And unlike...
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