0

I'm a novice programmer so please bear with me. I am running an user update API which returns a response object like this:

response: {
config: {
  url: 'https://admin.googleapis.com/admin/directory/v1/users/xxxxxxxx@xxxxx.solutions',
  method: 'PUT',
  userAgentDirectives: [Array],
  paramsSerializer: [Function (anonymous)],
  data: [Object],
  headers: [Object],
  params: {},
  validateStatus: [Function (anonymous)],
  retry: true,
  body: '{"password":"XXXXXXXXXX"}',
  responseType: 'json',
  retryConfig: [Object]
},
data: { error: [Object] },
headers: {
  'alt-svc': 'h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
  'cache-control': 'private',
  connection: 'close',
  'content-encoding': 'gzip',
  'content-type': 'application/json; charset=UTF-8',
  date: 'Thu, 15 Apr 2021 20:00:00 GMT',
  server: 'ESF',
  'transfer-encoding': 'chunked',
  vary: 'Origin, X-Origin, Referer',
  'x-content-type-options': 'nosniff',
  'x-frame-options': 'SAMEORIGIN',
  'x-xss-protection': '0'
},
status: 400,
statusText: 'Bad Request',
request: {
  responseURL: 'https://admin.googleapis.com/admin/directory/v1/users/xxxxxxxx@xxxxx.solutions'
}

}, config: { url: 'https://admin.googleapis.com/admin/directory/v1/users/xxxxxxxx@xxxxx.solutions', method: 'PUT', userAgentDirectives: [ [Object] ], paramsSerializer: [Function (anonymous)], data: { password: '12345678' }, headers: { 'x-goog-api-client': 'gdcl/5.0.2 gl-node/14.15.1 auth/7.0.3', 'Accept-Encoding': 'gzip', 'User-Agent': 'google-api-nodejs-client/5.0.2 (gzip)', Authorization: 'Bearer ya29.a0AfH6SMDxjWFzlvhDY1SHM_DKtDyfl5L7PLqMf1i1GP1MdFNX3-OorIzjqdfvGmIZWgf0sexxLanQZXtQRGyiMtct_ecH3l3hZGK7fHtmSzxedfUyczdrSG49eezMm8NmoAXm4iFA7JK_4HmGNpgxrhclObPfKIbhrtJoyiIMk3C56Gx9G7aZ4-OycGJfV6trYLRLzr927CnZhO95', 'Content-Type': 'application/json', Accept: 'application/json' }, params: {}, validateStatus: [Function (anonymous)], retry: true, body: '{"password":"xxxxxxxx@xxxxx"}', responseType: 'json', retryConfig: { currentRetryAttempt: 0, retry: 3, httpMethodsToRetry: [Array], noResponseRetries: 2, statusCodesToRetry: [Array] } }, code: 400, errors: [ { message: 'Invalid Password', domain: 'global', reason: 'invalid' } ] }

I am trying to extract the message inside the errors to display in a later page. How would I able to do that?

Sachin K
  • 25
  • 1
  • 6

1 Answers1

0

Please post your code. But you can try something like this.

response.data.error.forEach(error => {
  console.log(error.message);
})