Comments (3)
Btw, what's the best way to share actions through different methods. Let's say you have a meteor method that has 3 steps (actions) and then there is another method that needs to call 1 of the same actions, do you take it out to a different file and then export it? Do you put it within the imports/api or you put it on import/modules? Do you pass the promise through in case you need to reject it if an error happens?
Thanks
from pup.
Hi @tafelito customizing the error code in your own is best. The 500
is generic enough to alert that something went wrong on the server. Is the change you're proposing to pass the full exception
to the client?
Re: sharing actions, this depends. You can do an export const
of a specific method inside of an action, or, if it's something a bit more complex, just take that code and put it in its own file, importing it into both the action and the method. Both work but it's really a judgment call based on the work you're doing/how often the code will be reused.
from pup.
thanks @cleverbeagle for the answer. What I meant by customizing the error code is that when you throw an Meteor.Error from an action, then you are catching it on the method and throwing a new Meteor.Error with error code 500, so the cliente always get 500, not the one thrown in a specific action. Not sure If I'm being clear here
So if I have this
const action1 = ({ ... }) => {
try {
throw new Meteor.Error('600', 'Error msg');
} catch (exception) {
action.reject(`[handler.action1] ${exception}`);
}
};
const handler = ({ ... }, promise) => {
try {
action = promise;
action1(...);
action2(...); //this will be executed
action.resolve();
} catch (exception) {
action.reject(`[handler] ${exception}`);
}
};
Meteor.methods({
method(...) {
return handler({ ... })
.then(response => response)
.catch((exception) => {
throw new Meteor.Error('500', exception); // always returns error code 500, not 600
});
},
});
So right now, instead of sending the message from the reject, I return an object, with the message, and the exception itself and then in the catch I do this
.catch(({ exception, message }) => {
throw new Meteor.Error(exception.error, message);
});
It should have an extra validation though, in case the exception is not an actual Meteor.Error
from pup.
Related Issues (20)
- Real-time updates HOT 6
- How to Connect to a react native app with pupql HOT 4
- compose is not a function HOT 3
- Update Apollo Client and Apollo Server Usage HOT 4
- Application stuck when trying to run. HOT 4
- checkIfBlackListed does not work as expected! HOT 4
- Paste true may be necessary on e2e tests login helper
- Incorporate Code Splitting for Pup V2 & client side Redux HOT 9
- Access Meteor settings file from Jest? HOT 2
- graphQL httpUri on staging and production settings HOT 1
- How to upgrade from v1-> v2 HOT 3
- Add License File
- Wildcard instead of GraphQL? HOT 3
- Upgrade to latest version of alanning:roles HOT 1
- is this repo still maintained? HOT 9
- Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/graphql. (Reason: CORS request did not succeed). HOT 5
- Adding gql property to type user HOT 4
- Password only oauth possible? HOT 9
- Pup is moving!
- Apollo version and hooks HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pup.