• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Checking empty query parameter in nuxt

I have a search page on my Prismic/Nuxt project that makes a full-text query to the Prismic API.

This code will do that

export default {
  name: 'Search',
  async asyncData({ $prismic, params, query, error }) {
    try {
      // Query to get post content

      const products = await $prismic.api.query($prismic.predicates.fulltext('my.product.title', query.q), { orderings: '[my.product.title desc]' })
      // Returns data to be used in template
    
      return {
        products: products.results,
      }
    } catch (e) {    
      // Returns error page
      error({ statusCode: 404, message: 'Page not found' })
    }
  },
}

The URL is /search/?q=somesearch

The problem is that if I hit /search/ with no query parameter it will immediately hit the catch with the error Unable to encode undefined of type undefined, obviously because it tries to query the API with an undefined value, but I can't seem to find out how to make a valid check to don't query the API if no query is set and instead just show the search box.

I have tried with

if query.q !== undefined 

in the try section but that doesn't work.