Skip to content

Commit 84cc03a

Browse files
committed
fix: Fixes issue with headers crashing with empty context
1 parent b7a9825 commit 84cc03a

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @taskless/loader
22

3+
## 0.0.32
4+
5+
### Patch Changes
6+
7+
- Fixes empty context objects
8+
39
## 0.0.31
410

511
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@taskless/loader",
33
"description": "Taskless Loader - Take control of your third party APIs",
4-
"version": "0.0.31",
4+
"version": "0.0.32",
55
"author": "Taskless",
66
"license": "Apache-2.0",
77
"repository": "taskless/loader-js",

src/lib/sandbox.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const createSandbox = async (
4747
response: info.response
4848
? {
4949
status: info.response.status,
50-
headers: Object.fromEntries(info.response.headers.entries()),
50+
headers: [...info.response.headers.entries()],
5151
body: pack.permissions?.body
5252
? await extractBody(info.response)
5353
: undefined,
@@ -113,20 +113,26 @@ export const runSandbox = async (
113113
)
114114
);
115115

116-
// logger.debug(`[${requestId}] pack ran`);
116+
if (output) {
117+
const result = output?.json() as PluginOutput;
117118

118-
const result = output?.json() as PluginOutput;
119+
if (result.context) {
120+
context[`${index}`] = result.context;
121+
}
119122

120-
if (result.context) {
121-
context[`${index}`] = result.context;
123+
await callbacks.onResult(pack, result);
124+
logger.debug(`[${requestId}] (pre) pack ${pack.name} completed`);
125+
} else {
126+
logger.debug(
127+
`[${requestId}] (pre) pack ${pack.name} no output returned`
128+
);
122129
}
123-
124-
await callbacks.onResult(pack, result);
125130
})
126131
);
127132

128133
for (const hook of preHooks) {
129134
if (hook.status === "rejected") {
135+
logger.error(`${hook.reason}`);
130136
callbacks.onError(hook.reason);
131137
}
132138
}
@@ -180,18 +186,25 @@ export const runSandbox = async (
180186
)
181187
);
182188

183-
const result = output?.json() as PluginOutput;
189+
if (output) {
190+
const result = output?.json() as PluginOutput;
191+
if (result.context) {
192+
context[`${index}`] = result.context;
193+
}
184194

185-
if (result.context) {
186-
context[`${index}`] = result.context;
195+
await callbacks.onResult(pack, result);
196+
logger.debug(`[${requestId}] (post) pack ${pack.name} completed`);
197+
} else {
198+
logger.debug(
199+
`[${requestId}] (post) pack ${pack.name} no output returned`
200+
);
187201
}
188-
189-
await callbacks.onResult(pack, result);
190202
})
191203
);
192204

193205
for (const hook of postHooks) {
194206
if (hook.status === "rejected") {
207+
logger.error(`${hook.reason}`);
195208
callbacks.onError(hook.reason);
196209
}
197210
}

0 commit comments

Comments
 (0)