When trying to implement RFC9457 using Nuxt, I am having a problem sending the content-type "application/problem+json" to an error response using sendError, as shown in the example below:
if (allQueries.length > 0 && !hasValidQueries) {
setResponseHeaders(event, {
'Content-Type': 'application/problem+json',
});
// event.headers.set('Content-Type', 'application/problem+json');
// event.node.res.setHeader('Content-Type', 'application/problem+json');
return sendError(event, createError({
statusCode: 400,
statusMessage: 'Invalid query',
stack: event.context.clientAddress,
data: {
type: 'about:blank',
title: 'Bad Request',
status: 400,
detail: 'You can only use group_id or group_name as query.',
instance: event.path,
}
}))
}
None of the ways tried define the desired header, but if I comment out sendError and return a common message, like the example below, the header is defined.
if (allQueries.length > 0 && !hasValidQueries) {
setResponseHeaders(event, {
'Content-Type': 'application/problem+json',
});
return {
test: 'Send Erro'
}
}
Any idea what I should do to set a header using sendError?