|
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? |
Answered by
sholladay
Mar 27, 2025
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 |
1 reply
Answer selected by
The-LukeZ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm a little unclear on what you are trying to do. Is your goal to "unwrap" the nested
datafield such that the user can just usejsonrather 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.