Pattern to make a public view function return value only for owner of contract

Hello I am trying to make it so that my functions return value can only be visible by the owner of the contract I am using open zeppelin packages ownable but when I call this function right now I cannot get the return values even though I have a valid tokenId and I am sending the message as the owner, how I can implement this pattern ? thanks ahead

function getData(uint tokenId) public view returns (uint, uint, uint, uint, uint, uint){
  require(_exists(tokenId));
  require(bytes(IPFS_CIDs[tokenId]).length > 0 || _msgSender() == owner());

  return (data[tokenId][0],
          data[tokenId][1],
          data[tokenId][2],
          data[tokenId][3],
          data[tokenId][4],
          data[tokenId][5]
        );
}

What error messages did you get?

Hi @maxaero well I actually don't get one that's the hard part, when I use truffle console it works perfectly as I would expect but when I deploy on testnet and I execute on the read method tabs on ropsten etherscan i get [getTokenMetadata(uint256)** method Response]

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";

contract TestContract is ERC721Enumerable, Ownable {

	uint256 public constant MAX_TOKENS = 1;
	uint256 public constant NUM_METADATA = 4;
	uint8[NUM_METADATA][MAX_TOKENS] internal metadata;

	constructor () ERC721("TOKEN", "TKN") {
		safeMint();
		metadata[0][0] = 1;
		metadata[0][1] = 2;
		metadata[0][2] = 3;
		metadata[0][3] = 4;
	}

	function safeMint() public onlyOwner {
		_safeMint(owner(), totalSupply());
	}

	// Only show metadata if I am the owner of the contract
	function getTokenMetadata(uint tokenId) public view returns (uint, uint, uint, uint){
		require(_exists(tokenId), "ERC721Metadata: Query for nonexistent token");
  	    require(_msgSender() == owner(), 'Unauthorized');

		return (metadata[tokenId][0], metadata[tokenId][1], metadata[tokenId][2], metadata[tokenId][3]);
	}
}

Hey if you are still on this, MAX_TOKENS and NUM_METADATA should be switched, either positionally or numerically.

I think I understand the problem is because I am using etherscan in a read so not connected to metamask, when I interact with the contract from the console it works.
For the array declaration it works fine as well why should I inverse it ?
From my reading in Solidity, array dimensions are declared backwards from the way you might be used to declaring them in C or Java, but they are access as in C or Java.
I want a metadata array the size of MAX_TOKENS where each element is an array of 4 elements, where each element is a uint8.
Correct me if I'm wrong @maxaero

Look carefully, you have metadata[0][3] in your constructor but notice MAX_TOKENS, as the limit of second index, is only 1. You can either make MAX_TOKENS=4 and NUM_METADATA =1 or uint8[MAX_TOKENS][NUM_METADATA] internal metadata;.

metadata[0] is the first token index if do metadata[1][0] I go out of bound of the array.
I have the expected output I don't understand why I should change.
By delcaring the way I do have an array int8[4][0] internal metadata for the token id 0 I have 4 variables int8 type which is what I would like.
If I inverse like you say I will have one metada trait for 4 tokens which is not what I want @maxaero