Unhanble to access the error message in code

Hi everyone, I’m working on a custom app for freshsales suite. So I need to handle this error

    "errors": {
        "code": 400,
        "message": [
            "The cf_field already exists"

I need to identify when this error occurs, in order to do that, I tried to access the error object in many different ways, like so:

await $request.put(`https://domain.myfreshworks.com/crm/sales/api/sales_accounts/${id}`, header_put)
        function (data) {
         //success logic

        function (error) {
          //logic when an error occurs

          //i tried to see the error object in different ways

          //also tried to access message using an foreach because this attribute is a array
          let message;
          error.response.errors.message.forEach(text => {


            message = error.response.errors.message[text];


None of those ways worked and I don’t know what to do now. How can I access this attribute correctly?


Hi Matheus

Good day!

Can you please try printing the error message console.log(error) and add that here :slightly_smiling_face: .Also what was the output that you got for the different ways that you tried? These info might help us in finding what needs to be done

1 Like

Hi, I was trying to log those messages, but my custom app isn’t triggering anymore when a account is created, don’t know why this is happening. I’ll create a post for this issue, once I resolve that, I’ll post the logs here.

Hi, apparently the problem I was facing resolved itself, I don’t know what happened but ok.

To answer your question, here are the console.log() resolts:

console.log(error); :

{ status: 400, headers: { date: 'Fri, 11 Mar 2022 20:19:56 GMT', 'content-type': 'application/json; charset=utf-8', 'transfer-encoding': 'chunked', connection: 'close', status: '400 Bad Request', 'cache-control': 'no-cache', 'x-ratelimit-limit': '5000', 'x-ratelimit-reset': '110322203436', 'strict-transport-security': 'max-age=31536000; includeSubDomains', 'x-ratelimit-remaining': '4988', vary: 'Origin', 'x-request-id': 'c239e3f2-049f-40e5-b99a-fa3dee0b1b3f', 'x-ua-compatible': 'IE=Edge,chrome=1', 'x-frame-options': 'DENY', 'x-envoy-upstream-service-time': '115', server: 'fwe', 'x-trace-id': '00-ca043efb15ff8298175e27da80cf0a8c-f3dd5054fed53f93-00', 'x-fw-ratelimiting-managed': 'false' }, response: '{"errors":{"code":400,"message":["The cf_cnpj already exists"]}}', attempts: 1, errorSource: 'APP' }



The other logs, like console.log(error.response.errors.message); and console.log(error.response.errors.message[0]); didn’t even return anything, and after that the code brutally ends, not even reaching the foreach, which is a behavior that shouldn’t happen…

Hi Matheus,

To console log the error messages can you please try this - console.log(JSON.parse(error.response).errors.message)


This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.