Skip to content

Commit 1f26fde

Browse files
Remove type guards
1 parent 6d641c4 commit 1f26fde

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed
Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
Headers,
3-
WebhookHandlerFileReturnType,
4-
WebhookHandlerJsonReturnType,
5-
WebhookHandlerReturnType,
6-
WebhookHandlerTextReturnType,
7-
WebhookResponseType,
8-
} from '@boostercloud/rocket-webhook-types'
1+
import { Headers, WebhookHandlerReturnType, WebhookResponseType } from '@boostercloud/rocket-webhook-types'
92
import { WebhookFileResponse } from './responder/webhook-file-response'
103
import { WebhookJsonResponse } from './responder/webhook-json-response'
114
import { WebhookTextResponse } from './responder/webhook-text-response'
@@ -28,20 +21,20 @@ export class WebhookResponseBuilder {
2821
this.webhookBaseResponse = new WebhookEmptyResponse()
2922
return
3023
}
31-
if (this.isFile(response)) {
32-
this.webhookBaseResponse = new WebhookFileResponse()
33-
return
34-
}
35-
if (this.isJson(response)) {
36-
this.webhookBaseResponse = new WebhookJsonResponse()
37-
return
24+
switch (response.responseType) {
25+
case WebhookResponseType.file:
26+
this.webhookBaseResponse = new WebhookFileResponse()
27+
return
28+
case WebhookResponseType.json:
29+
this.webhookBaseResponse = new WebhookJsonResponse()
30+
return
31+
case WebhookResponseType.text:
32+
this.webhookBaseResponse = new WebhookTextResponse()
33+
return
34+
default:
35+
console.log('Unexpected response type. Using File')
36+
this.webhookBaseResponse = new WebhookFileResponse()
3837
}
39-
if (this.isText(response)) {
40-
this.webhookBaseResponse = new WebhookTextResponse()
41-
return
42-
}
43-
console.log('Unexpected response type. Using File')
44-
this.webhookBaseResponse = new WebhookFileResponse()
4538
}
4639

4740
public getBody(): unknown {
@@ -56,16 +49,4 @@ export class WebhookResponseBuilder {
5649
const customHeaders = this.webhookBaseResponse.getHeaders(this.response)
5750
return { ...headers, ...customHeaders }
5851
}
59-
60-
private isText(response: WebhookHandlerReturnType): response is WebhookHandlerTextReturnType {
61-
return (response as WebhookHandlerTextReturnType).responseType === WebhookResponseType.text
62-
}
63-
64-
private isJson(response: WebhookHandlerReturnType): response is WebhookHandlerJsonReturnType {
65-
return (response as WebhookHandlerJsonReturnType).responseType === WebhookResponseType.json
66-
}
67-
68-
private isFile(response: WebhookHandlerReturnType): response is WebhookHandlerFileReturnType {
69-
return (response as WebhookHandlerFileReturnType).responseType === WebhookResponseType.file
70-
}
7152
}

0 commit comments

Comments
 (0)