-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(utils/query): Add try-catch block to handle exceptions in query f…
…unction execution The try-catch block is added to the execution of the query function in order to handle exceptions that might occur before returning the observable. This ensures that any errors thrown during the execution are caught and properly handled, preventing the process from terminating prematurely. Updated test-case to validate exceptions in query client
- Loading branch information
Showing
3 changed files
with
54 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
'@equinor/fusion-query': patch | ||
--- | ||
|
||
Added try catch block to execution of query function, since the method might throw an exception before returning the observable. | ||
|
||
```ts | ||
const queryClient = new Query({ | ||
client: { | ||
() => { | ||
throw new Error('this would terminate the process before'); | ||
return new Observable((subscriber) => { | ||
throw new Error('this worked before'); | ||
}); | ||
}, | ||
}, | ||
key: (value) => value, | ||
|
||
queryClient.query().subscribe({ | ||
error: (error) => { | ||
// before changes this would not be called since stream would be terminated. | ||
console.log(error.message); // this would print 'this would terminate the process before' | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters