diff --git a/index.ts b/index.ts index 00437b4..b17f259 100644 --- a/index.ts +++ b/index.ts @@ -16,6 +16,7 @@ fs.watch(path, async function (event, filename) { if (!['GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'].includes(method)) { return } + requestData.Response = {Headers: {}} try { const res = await got({ url: requestData.Request.URL, @@ -26,7 +27,7 @@ fs.watch(path, async function (event, filename) { requestData.Response.StatusCode = res.statusCode Object.keys(res.headers).forEach((e) => { - requestData.Response.Headers[e] = res.headers[e] + if (requestData.Response) requestData.Response.Headers[e] = res.headers[e] }) requestData.Response.Body = res.body } catch (error) { diff --git a/types.ts b/types.ts index edcabc8..4bd6060 100644 --- a/types.ts +++ b/types.ts @@ -2,13 +2,13 @@ export interface IrequestData { Request: { Mode: string URL: string - Headers: any - Body: string + Headers?: any + Body?: string } - Response: { - StatusCode: number + Response?: { + StatusCode?: number Headers: any - Body: string + Body?: string } Processed?: boolean }