Here are the eslint errors that occurred with the code provided:
@typescript-eslint/no-unsafe-member-access: Unsafe member access ['content-type'] on an any value.
export const fetchGraphPhoto = async () => {
try {
const response = await fetchGraphInfo(
config.resources.msGraphPhoto.uri,
config.resources.msGraphPhoto.scopes,
{ responseType: 'arraybuffer' }
);
if (!(response && response.data)) {
return '';
}
const imageBase64 = new Buffer(response.data, 'binary').toString('base64');
return `data:${response.headers['content-type']};base64, ${imageBase64}`;
} catch (error) {
throw new Error(`Failed to retrieve the graph photo: ${error as string}`);
}
}
The promise fetchGraphInfo
returns Promise<AxiosResponse<any>>
The problem lies in trying to access the property response.headers['content-type']
which may not exist. I attempted to check for its presence but the warning persists:
if (
!(response && response.data && response.headers && response.headers['content-type'])
) { return ''; }
I appreciate any help to understand and resolve this issue better.