Personally, I do not like to handle errors that way, I consider them incorrect, I leave you the link so you can take a look about making these exceptions: developer.mozilla.org/docs/Web/Jav...
asyncfunctiongetUser(id:number):Promise<User>{// We throw an exception.if(id<=0)thrownewError("Wrong, id can't be less or equal to zero!!!");// Result.return{id,email:"abc@domain.com"};}
asyncfunctiongetUserData(id:number):Promise<Result<UserData>>{if(id<=0){return{error:newError("Wrong, id can't be less or equal to zero!!!");}}return{result:{name:"Jimmy",age:22},}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you for your contribution, my friend.
Personally, I do not like to handle errors that way, I consider them incorrect, I leave you the link so you can take a look about making these exceptions: developer.mozilla.org/docs/Web/Jav...
Now we handle it.
Sure, I actually like the golang pattern because is easy to read.
Also I got a different approach by asking about this.