export interface ResponseError = [any, Error]; // Tuple to return either
/**
* special promise trap to build tuple of reponse and error
*/
const trap = (promise): Promise<ResponseError> => {
return promise
.then(data => ([data, undefined]))
.catch(error => Promise.resolve([undefined, error]));
}
async assignUserToTask(taskId: string, user: User): ResponseError {
const [url, body, options] = buildParams(taskId, user);
this.updateState({ loading: true }); // start loading
const request$ =this.http.put<Task>( url, body, options);
const [updated, error] = await trap( request$.toPromise() );
this.updateState({ loading: false }); // stop loading
return [ updated, error ];
}
Last active
January 14, 2020 04:45
-
-
Save ThomasBurleson/653810b0c39fc013de8b53c96198d4af to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment