0

In my Angular application upon successfully making a POST to the server I receive a 201 response containing a location in the response headers that I wish to access inside my NGRX Effects. The location contains an id which I need in another effect to trigger a service call.

enter image description here

NGRX ACTION:

export const postJobOfferSuccess = createAction('[JobOffer] Post jobOffer success', props<{ successMessage: string, publish: boolean, final: boolean, response: HttpHeaderResponse }>());

NGRX EFFECT:

postJobOffer$ = createEffect(() =>
    this.actions$.pipe(
        ofType(postJobOffer),
        mergeMap(action => {
            return this.jobOfferClientService.postJobOffer(action.jobOffer).pipe(
                map((response) => postJobOfferSuccess({ successMessage: 'Success', publish: action.publish, final: action.final, response: response.HttpHeaderResponse })),
                mapErrorToAction(postJobOfferFailed)
            );
        })
    )
);

I would expect my postJobOfferSuccess to contain a response with the HTTPHeaderResponse, however upon inspecting my redux tab it does not show the header response. How can I access HTTPHeaderResponse inside an effect?

my redux tab:

enter image description here

1 Answer 1

1

In your service you have to listen to the response :


this.http.post('http//...', payload, { observe: 'response' }).pipe(
  tap(res => console.log(res)) // headers = res.headers | data = res.body
);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.