Is it good to make api call made in try-catch block or outside, in redux-saga?Fail try/catch block reading a csvHow to test API request failures with Redux Saga?Asynchronous api calls with redux-sagatesting try-catch in redux-sagaHow to catch exceptions in an NSBlockOperation while in unit tests?Redux-Saga takeEvery not calling sagaTest Redux-Saga 'yield call'Redux saga channel blocking inconsistentlyHow to write C# unit test for proper code coverage in try catch blockCalling component methods after redux-saga API call completion: use componentDidUpdate or pass the method to the action creator?
Won 50K! Now what should I do with it
3D-Plot with an inequality condition for parameter values
Do native speakers use ZVE or CPU?
Concatenation using + and += operator in Python
Add region constraint to Graphics
Replacing URI when using dynamic hosts in Nginx reverse proxy
Adding a vertical line at the right end of the horizontal line in frac
Why use null function instead of == []
How are "soeben" and "eben" different from one another?
Would letting a multiclass character rebuild their character to be single-classed be game-breaking?
Does entangle require vegetation?
Book or series about stones and a magician named Gwydion
Can a pizza stone be fixed after soap has been used to clean it?
Why is "dark" an adverb in this sentence?
Are there any double stars that I can actually see orbit each other?
Why do legislative committees exist?
Is this a Lost Mine of Phandelver Plot Hole?
Aborting 'wrong username' logins
Is killing off one of my queer characters homophobic?
Too many spies!
Absconding a company after 1st day of joining
Deep Learning based time series forecasting
Ezek. 24:1-2, "Again in the ninth year, in the tenth month, in the tenth day of the month, ...." Which month was the tenth month?
Doing research in academia and not liking competition
Is it good to make api call made in try-catch block or outside, in redux-saga?
Fail try/catch block reading a csvHow to test API request failures with Redux Saga?Asynchronous api calls with redux-sagatesting try-catch in redux-sagaHow to catch exceptions in an NSBlockOperation while in unit tests?Redux-Saga takeEvery not calling sagaTest Redux-Saga 'yield call'Redux saga channel blocking inconsistentlyHow to write C# unit test for proper code coverage in try catch blockCalling component methods after redux-saga API call completion: use componentDidUpdate or pass the method to the action creator?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a following function in my saga.ts file :
export function* getProductsList(action)
yield put(productsListAttempt(true));
const productsList = yield api.getProductsList();
try
yield put(productsListSuccess(productsList));
catch
yield put(productsListError('Error occured'));
I am trying to write a unit test for this function. The problem I am encountering with this is, whenever I execute my test for FAILURE of the function it does not pass well. It never gives result as per the catch block. But when I put this line: const productsList = yield api.getProductsList();
in the try block then the test pass as per expectation.
-- Is it really good to put api call outside try block or not? Why so ?
reactjs unit-testing redux-saga
|
show 1 more comment
I have a following function in my saga.ts file :
export function* getProductsList(action)
yield put(productsListAttempt(true));
const productsList = yield api.getProductsList();
try
yield put(productsListSuccess(productsList));
catch
yield put(productsListError('Error occured'));
I am trying to write a unit test for this function. The problem I am encountering with this is, whenever I execute my test for FAILURE of the function it does not pass well. It never gives result as per the catch block. But when I put this line: const productsList = yield api.getProductsList();
in the try block then the test pass as per expectation.
-- Is it really good to put api call outside try block or not? Why so ?
reactjs unit-testing redux-saga
In many of the tutorials which I referred to learn Redux-saga, the api call was in the Try block. But at my work, my seniors has put it outside the try-catch block
– NRJ
Mar 21 at 15:54
Not sure why you are not sure. Better to put it in thetry
so you can test it but more importantly so you can react in the real usage scenario.
– Gabriele Petrioli
Mar 21 at 15:54
@GabrielePetrioli other than the unit test scenarios, it does not cause any problem.
– NRJ
Mar 21 at 15:58
perhaps there is global error handling in the app and so they do not want the error handled locally.
– Gabriele Petrioli
Mar 21 at 16:02
@GabrielePetrioli when it make a call to the function productsListError('Error occurred'), they set this string message to the state in reducer and then show it on the view. Other than that there is no error handling logic.
– NRJ
Mar 21 at 16:15
|
show 1 more comment
I have a following function in my saga.ts file :
export function* getProductsList(action)
yield put(productsListAttempt(true));
const productsList = yield api.getProductsList();
try
yield put(productsListSuccess(productsList));
catch
yield put(productsListError('Error occured'));
I am trying to write a unit test for this function. The problem I am encountering with this is, whenever I execute my test for FAILURE of the function it does not pass well. It never gives result as per the catch block. But when I put this line: const productsList = yield api.getProductsList();
in the try block then the test pass as per expectation.
-- Is it really good to put api call outside try block or not? Why so ?
reactjs unit-testing redux-saga
I have a following function in my saga.ts file :
export function* getProductsList(action)
yield put(productsListAttempt(true));
const productsList = yield api.getProductsList();
try
yield put(productsListSuccess(productsList));
catch
yield put(productsListError('Error occured'));
I am trying to write a unit test for this function. The problem I am encountering with this is, whenever I execute my test for FAILURE of the function it does not pass well. It never gives result as per the catch block. But when I put this line: const productsList = yield api.getProductsList();
in the try block then the test pass as per expectation.
-- Is it really good to put api call outside try block or not? Why so ?
reactjs unit-testing redux-saga
reactjs unit-testing redux-saga
asked Mar 21 at 15:52
NRJNRJ
351 silver badge6 bronze badges
351 silver badge6 bronze badges
In many of the tutorials which I referred to learn Redux-saga, the api call was in the Try block. But at my work, my seniors has put it outside the try-catch block
– NRJ
Mar 21 at 15:54
Not sure why you are not sure. Better to put it in thetry
so you can test it but more importantly so you can react in the real usage scenario.
– Gabriele Petrioli
Mar 21 at 15:54
@GabrielePetrioli other than the unit test scenarios, it does not cause any problem.
– NRJ
Mar 21 at 15:58
perhaps there is global error handling in the app and so they do not want the error handled locally.
– Gabriele Petrioli
Mar 21 at 16:02
@GabrielePetrioli when it make a call to the function productsListError('Error occurred'), they set this string message to the state in reducer and then show it on the view. Other than that there is no error handling logic.
– NRJ
Mar 21 at 16:15
|
show 1 more comment
In many of the tutorials which I referred to learn Redux-saga, the api call was in the Try block. But at my work, my seniors has put it outside the try-catch block
– NRJ
Mar 21 at 15:54
Not sure why you are not sure. Better to put it in thetry
so you can test it but more importantly so you can react in the real usage scenario.
– Gabriele Petrioli
Mar 21 at 15:54
@GabrielePetrioli other than the unit test scenarios, it does not cause any problem.
– NRJ
Mar 21 at 15:58
perhaps there is global error handling in the app and so they do not want the error handled locally.
– Gabriele Petrioli
Mar 21 at 16:02
@GabrielePetrioli when it make a call to the function productsListError('Error occurred'), they set this string message to the state in reducer and then show it on the view. Other than that there is no error handling logic.
– NRJ
Mar 21 at 16:15
In many of the tutorials which I referred to learn Redux-saga, the api call was in the Try block. But at my work, my seniors has put it outside the try-catch block
– NRJ
Mar 21 at 15:54
In many of the tutorials which I referred to learn Redux-saga, the api call was in the Try block. But at my work, my seniors has put it outside the try-catch block
– NRJ
Mar 21 at 15:54
Not sure why you are not sure. Better to put it in the
try
so you can test it but more importantly so you can react in the real usage scenario.– Gabriele Petrioli
Mar 21 at 15:54
Not sure why you are not sure. Better to put it in the
try
so you can test it but more importantly so you can react in the real usage scenario.– Gabriele Petrioli
Mar 21 at 15:54
@GabrielePetrioli other than the unit test scenarios, it does not cause any problem.
– NRJ
Mar 21 at 15:58
@GabrielePetrioli other than the unit test scenarios, it does not cause any problem.
– NRJ
Mar 21 at 15:58
perhaps there is global error handling in the app and so they do not want the error handled locally.
– Gabriele Petrioli
Mar 21 at 16:02
perhaps there is global error handling in the app and so they do not want the error handled locally.
– Gabriele Petrioli
Mar 21 at 16:02
@GabrielePetrioli when it make a call to the function productsListError('Error occurred'), they set this string message to the state in reducer and then show it on the view. Other than that there is no error handling logic.
– NRJ
Mar 21 at 16:15
@GabrielePetrioli when it make a call to the function productsListError('Error occurred'), they set this string message to the state in reducer and then show it on the view. Other than that there is no error handling logic.
– NRJ
Mar 21 at 16:15
|
show 1 more comment
1 Answer
1
active
oldest
votes
There's nothing wrong putting the call inside a try/catch block, I do the same in my projects and it's fine because the call can fail and the try/catch let you, by definition, manage this error case 😉
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284383%2fis-it-good-to-make-api-call-made-in-try-catch-block-or-outside-in-redux-saga%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There's nothing wrong putting the call inside a try/catch block, I do the same in my projects and it's fine because the call can fail and the try/catch let you, by definition, manage this error case 😉
add a comment |
There's nothing wrong putting the call inside a try/catch block, I do the same in my projects and it's fine because the call can fail and the try/catch let you, by definition, manage this error case 😉
add a comment |
There's nothing wrong putting the call inside a try/catch block, I do the same in my projects and it's fine because the call can fail and the try/catch let you, by definition, manage this error case 😉
There's nothing wrong putting the call inside a try/catch block, I do the same in my projects and it's fine because the call can fail and the try/catch let you, by definition, manage this error case 😉
answered Mar 26 at 6:40
NoriSteNoriSte
1,4801 gold badge10 silver badges9 bronze badges
1,4801 gold badge10 silver badges9 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284383%2fis-it-good-to-make-api-call-made-in-try-catch-block-or-outside-in-redux-saga%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In many of the tutorials which I referred to learn Redux-saga, the api call was in the Try block. But at my work, my seniors has put it outside the try-catch block
– NRJ
Mar 21 at 15:54
Not sure why you are not sure. Better to put it in the
try
so you can test it but more importantly so you can react in the real usage scenario.– Gabriele Petrioli
Mar 21 at 15:54
@GabrielePetrioli other than the unit test scenarios, it does not cause any problem.
– NRJ
Mar 21 at 15:58
perhaps there is global error handling in the app and so they do not want the error handled locally.
– Gabriele Petrioli
Mar 21 at 16:02
@GabrielePetrioli when it make a call to the function productsListError('Error occurred'), they set this string message to the state in reducer and then show it on the view. Other than that there is no error handling logic.
– NRJ
Mar 21 at 16:15