Practice ยท 2 of 3
Discriminated API Result
Write toApiResult(promise) โ awaits the promise and returns { ok: true, data } on success, { ok: false, status: 0, message: err.message } on failure. Write unwrap(result) โ returns data when ok, else THROWS an Error with the stored message. The pair must compose: unwrap(toApiResult(p)) returns the value or throws.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Mini Build: Typed API Model