QueryContacts returning 'Unable to handle the request'

@lexi-datta I looked at your code and I suspect it is happening in your backend code. The code is failing when trying to access info.

What I suspect is happening is your query is not returning any results. So you end up with an empty recordset being returned.

You are trying to use

const userType = results.items[0].info.extendedFields["custom.user"];

but you are not doing any validation to ensure you got records returned.
I’ve adjusted your backend code a bit, and put in some error checking. I also changed some of the ‘const’ declaration to ‘let’. I find that a lot of examples misuse ‘const’.

Here is the changed code, see if this helps. I have also included a few console.log() messages that should give you some help if something goes wrong.

import { contacts } from 'wix-crm-backend';

export async function myUserType( email ) {
    return contacts.queryContacts()
    .eq('primaryInfo.email', email)
    .find({'suppressAuth': true})
    .then( (results) =>{
        if (results.length >0) {
            let userType = results.items[0].info.extendedFields["custom.user"];
            return userType;
        } else {
            console.log("[myUserType]::No record was found when querying queryContacts.  Email was: "+email);
            return ""; // no record was returned so return blank usertype
        }
    })
    .catch( (error) => {
        console.log("[myUserType]::Error occured trying to run queryContacts.  Error was: "+ error.message);
        return ""; // no record was returned so return blank usertype
    });
}  
   

I changed your style a little bit. I saw this similar example using this style at:

I was not able to test to run this so hopefully I didn’t make a mistake in typing.

A very important thing to note is the backend query uses .eq().
That means the email must match exactly. The alphabetic case (upper/lower) has to match exactly and there can’t be any spaces etc. If it does not match exactly, your query will fail and you will not get back any results.

You could also try replacing the .eq() with

.contains('primaryInfo.email', email)

Using .contains(), is more forgiving in that it is a case insensitive search and will still find it if there are spaces after it.