added error checking in query

Added to support when layer does not exist