-
I have a hook like this: hooks: {
afterResponse: [
async (_input, _options, response) => {
const _json = await response.json<any>();
if (!response.ok) {
throw new Error(_json?.errors || response.statusText);
}
return "data" in response ? response.data : _json;
},
],
}, How do I access the json body now? Additionally, can I improve this somehow? Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'm a little unclear on what you are trying to do. Is your goal to "unwrap" the nested If so, then you could |
Beta Was this translation helpful? Give feedback.
I'm a little unclear on what you are trying to do. Is your goal to "unwrap" the nested
data
field such that the user can just usejson
rather thanjson.data
?If so, then you could
return new Response(JSON.stringify(json.data))
. Make sure to also pass in the content type header and status as options.