How to see status of request in angular?

Viewed 27

I return the context and status code from Django rest API as follows

Admin.objects.get(email_id = request.data.get('email_id'), password = request.data.get('password'))
            context = {'resp' : 'Login details are valid..!'}
            return Response(context,status=status.HTTP_200_OK)

How can I access this status in angular?

I try this but I am getting undefined

this.apiCallService.admin_signup(fd).subscribe((response:any)=>
    {
      this.spinnerFlag = false;
      console.warn(response.status);
      ----------

How to fix this issue?

console.log() =>

{resp: 'Account created successfully...!'}
1 Answers

you can write an interceptor and get all status code of all response from your backend.

if you just want to get status code of this api call you can return status code in json returned from your backend. for example in a try catch block:

in try:

context = {'resp' : 'Login details are valid..!', 'status':'200'}

in catch:

context = {'resp' : 'Login details are invalid..!', 'status':'500'}
Related