How to extract value that is thrown from an error object [closed]

I am using typescript. The code is as follows

if (!response.ok)  {
      const errorData = (await response.json());
      throw {
        foo: "bar",
        error: errorData
      };
}

When i try to parse the object it is displayed as follows

catch (error: any) {
        console.log(error) //returns Error: {foo: "bar", error: ..., digest: ...}
        console.log(error.message); // returns {foo: "bar", error: ..., digest: ...}
        console.log(error.foo); //undefined
        console.log(error.message.foo); // undefined

    }

How do i extract the value of foo from the error data?