Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to stop execution if one of the tasks failed?
Message
From
28/03/2018 13:56:39
 
General information
Forum:
Javascript
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01659020
Message ID:
01659048
Views:
41
This message has been marked as a message which has helped to the initial question of the thread.
>>>Hi everybody,
>>>
>>>I have the following code:
>>>
>>>
>>>load($stateParams.draftId);
>>>
>>>                getMetaData();
>>>...
>>>
>>>
>>>The load method has this code:
>>>
>>> spinnerService.startSpinner('loaditemtree');
>>>                   
>>>                    loadItemTreeRoot(draftId);
>>>                    loadUnassigned(draftId);
>>>
>>>
>>>The last 2 load functions as well as getMetaData call some service which returns promise. My problem is that I don't want to execute extra code if, for example, the very first method loadItemTreeRoot already returns a bad status.
>>>
>>>How can I re-write the above to make sure my methods are executed in the synchronous fashion, to be precise, once one method failed (returned bad request), the rest of my methods are not executed?
>>>
>>>Thanks in advance.
>>
>>You just need to chain your promises. e.g:
loadItemTreeRoot(draftId).then(function (success){
>>        loadUnassigned(draftId);
>>}, function(error){
>>    /whatever
>>})
Ditto for the outer call to handle the loadUnassigned promise
>
>I was thinking about it, but that was developed by other developer and he probably had a reason to make all of them as separate functions and sometimes call all of them (in the initial load) and sometimes just one of them.

So how is the promise handled in each of the methods ?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform