Uh oh!
There was an error while loading. Please reload this page.
First of all, thank you for this great project! I currently get the following error message with Angular: This is my code: publicgetTaskById(id: string,): Result<QueryObserverResult<Task|undefined,Error>>{returnthis.#query({queryKey: ['tasks',id],queryFn: ()=>this.tasksService.getTaskById(id),});}As you can see, I am searching an entity I understand the error message. However, I wonder what the best practices are to implement this. |
Replies: 2 comments
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Not definitely an expert but I'm also curious to know the answer. Anyway in my opinion:
{ queryKey: ['tasks',id]queryFn: ()=>this.taskService.getTaskById(id).then((data)=>{if(data){thrownewMyCustomError()}returndata}),retry? // ... handle logic for MyCustomErrorthrowOnError? // handle logic for MyCustomError} |
if you want the query go to into error state when the item does not exist, you can check and throw a custom error as the answer by @riccardoperra shows. if you're fine with having no data for a successfully resolved query, I'd just transform to of course you could also change |
if you want the query go to into error state when the item does not exist, you can check and throw a custom error as the answer by @riccardoperra shows.
if you're fine with having no data for a successfully resolved query, I'd just transform to
nullbecause that is allowed:of course you could also change
getTaskByIdto already returnnull.