Could you tell me how can I return Observable
here? I have tried many ways. But no success yet.
[ts] A function whose declared type is neither 'void' nor 'any' must return a value.
deleteInvite(inviteId):Observable<HttpResponse<Object>> {
this.getHttpHeader().then(headers => {
return this.http.post(this.apiURL + "/deleteInvite", inviteId, { observe: "response", headers: headers })
}).catch(err => {
console.error(err);
});
}
async getHttpHeader() {
const accessToken = await this.getJWTToken();
let headers = new HttpHeaders().set('Authorization', `Bearer ${accessToken}`);
return headers;
}
FOR rxjs version: 6.0.0 onwards
import { from } from 'rxjs';
deleteInvite(inviteId):Observable<HttpResponse<Object>> {
return from(this.getHttpHeader()).pipe(
switchMap(headers => {
return this.http.post(this.apiURL + "/deleteInvite", inviteId, { observe: "response", headers: headers })
}),
catchError(err => {
console.error(err);
})
);
}
For older versions of rxjs:
Convert the thisGetHeaders()
to an Observable by using fromPromise
import { fromPromise } from 'rxjs/observable/fromPromise';
deleteInvite(inviteId):Observable<HttpResponse<Object>> {
return fromPromise(this.getHttpHeader()).pipe(
switchMap(headers => {
return this.http.post(this.apiURL + "/deleteInvite", inviteId, { observe: "response", headers: headers })
}),
catchError(err => {
console.error(err);
})
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With