At some point of a process I’m using http request activity to download some files from a webservice.
If response status is 200 everything went ok, else something went wrong.
The problem: The activity does not throw an error if I for example get a 502 status witch means that the server was not responding so I basically want to:
- Capture the status of the response - Done and tested
- Force properly business exception in case status is not 200
- The process should continue, and set transaction status to failed by business
Another question is: The moment I force that business exception what the process will do?
I mean it will continue till the end and then setting up the status and getting next transaction item? Will stop the process at that point and set status and get another item? Or will stop the process and re-initialize everything to continue with the next item in the queue?
Thanks in advance,
You use the Throw activity to generate exceptions manually.
If you do not have the Throw inside a Try/Catch the job will immediately terminated as failed.
Typically you want to use Try/Catch to handle the exception. Put your steps in the Try block and when the exception is encountered it skips the rest of the steps and jumps to the appropriate Catch block where you perform your exception steps such as taking screenshots, sending emails, setting transaction status etc
Well in order to force a business exception in the case where the HTTP request status is not 200, you can use the following steps:
- Surround the https activity within try block of a try catch activity
Then add a new Throw activity in catch block
- Set the Exception property of the Throw activity to a New BusinessRuleException(“Failed to download file from web service”.)
This will ensure that the process fails with a business exception if the HTTP request status is not 200.
Whether the process will continue or stop after throwing the business exception depends on where the
Throw activity is placed in the process.
Throw activity is placed at the end of the process, the process will stop and the transaction status will be set to failed.
Throw activity is placed in the middle of the process, the process will continue to the next activity after the
Hope this clarifies
This is the logic now:
I have a few questions:
- The throw is in the Try block but the catch block is empty because how do I capture a non predefined excepction such as this one: New BusinessRuleException(“Failed to download file from web service”)
- After the try-catch as you can see there is more activities. My intended behaviour is that one the process throw and catch the business, the Process in reframework stops and then set the status transaction to failed with the business.
How can I continue with this?
You have mentioned a custom exception,
BusinessRuleException, with a message like “Failed to download file from the web service.”
Here’s how you can capture and handle it:
- In your workflow, place the activity that may throw the
BusinessRuleException within a
Try Catch activity.
- In the
Try block, include the activity that might throw the exception.
- In the
Catch block, add a
Catch activity for
BusinessRuleException. To do this, click the “Add Exception” button within the
Catch block, and select the
- Inside the
Catch block for the
BusinessRuleException, you can add activities to handle the exception. This might include logging the error, displaying a message to the user, or taking any other appropriate action.
Here are the steps to implement this behavior:
1.In your workflow, within the
Catch block for the
BusinessRuleException, log the error message and then rethrow the exception:
2.you should have a mechanism to catch unhandled exceptions at a higher level, which can be done in the
Process.xaml file. In the
Process.xaml , you can add a
Try Catch block to catch any unhandled exceptions
By configuring the
Process.xaml this way, any unhandled exceptions, including the
BusinessRuleException that is rethrown in your specific workflow, will be caught at this level. You can then log the error, set the transaction status to “Failed,” and the framework will handle it accordingly.
Note : - This approach ensures that when a BusinessRuleException is caught, it propagates to the framework, and the transaction status is set to “Failed,” stopping the process as intended.
I’m getting half of what you say and I think is because my fault, I’ll try to give more details:
- I’m using reframework
- Since is it a simple process, the activity HTTP Request is placed in Process.xaml . The process that comes with the template. I know normaly this process is just a set of simple actions and it is used to invoke another handmade sub-processes using try-catch to do it. But in this case all the logic is directly implemented in the process since it is create a few folders and move the downloaded file from one to another.
- Basically what the process is doing is calling a webservice with some data retrieved from the queue. This should download a file in a specific folder and then move it to another one.
- The problem is that when Response Status is not 200, the activity does not throw per se an excepction. It just return the error code for example 404 and a message with the text for example Resource not found or whatever.
- When this happens the file is saved as it everything were ok but it didnt obviously.
- So I placed after that an if that checks if Response Status is 200 ( OK ).
- If it is 200 then I have not problem.
- If it is not 200 then I want to set up a business exception as you helped me.
- Now I use a throw in the Else block with: new Business…
- If I place this block of actions (http request + if ) in the Try Catch and Catch the new Business rule exception then the catch actions are performed. But the process will continue with more actions that I dont want to do.
The intended behaviour is that the throw implies that the process for that item finish in the catch block then gets out of Process.xaml and then set status transaction to business rule with the message I set up.
Within the “Catch” block where you catch the Business Rule Exception, you can add a “Throw” activity to rethrow the exception. This will stop the current execution and move to the next transaction item process the next queue item, effectively skipping any further actions within the current iteration.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.