Don't use ContinueWith. Just use await. A faulted Task will throw an exception on await that you can catch and handle.
try { var response = await _service.GetProfile(code); // Here Task is complete without an exception } catch(Exception ex) { // Task has faulted return object; }
Note that your test method has to be marked async.
In order to write unit tests for asynchronous code without using await, use synchronization objects like a ManualResetEvent.
See my answer here: "Thread was being aborted." in test that tests code that fires a delegate on a background thread
ContinueWithat all; useawaitinstead.