-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CAI-181] update lambda trigger (#1208)
* add healthz call on chatbot popup * add changeset * Move getHealthz code on separate script * remove solutions.ts empty file, move makeError to file
- Loading branch information
Showing
9 changed files
with
50 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nextjs-website": patch | ||
--- | ||
|
||
Add healthz call on chatbot popoup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { pipe } from 'fp-ts/lib/function'; | ||
import { ChatbotEnv } from '@/lib/chatbot/chatbotEnv'; | ||
import * as E from 'fp-ts/lib/Either'; | ||
import * as R from 'fp-ts/lib/Reader'; | ||
import * as TE from 'fp-ts/lib/TaskEither'; | ||
import { makeError } from '../makeError'; | ||
|
||
export const getHealthz = () => | ||
pipe( | ||
R.ask<ChatbotEnv>(), | ||
R.map(({ config: { CHATBOT_HOST: chatbotHost }, getAuthToken, fetch }) => | ||
pipe( | ||
// handle any promise result | ||
TE.tryCatch(() => getAuthToken(), E.toError), | ||
TE.chainTaskK( | ||
(authToken) => () => | ||
fetch(`${chatbotHost}/healthz`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${authToken}`, | ||
}, | ||
}) | ||
), | ||
TE.chain((response) => { | ||
if (response.status === 200) { | ||
return TE.tryCatch(() => response.json(), E.toError); | ||
} else { | ||
return TE.left(makeError(response)); | ||
} | ||
}) | ||
)() | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const makeError = ({ status, statusText }: Response) => { | ||
return new Error(`${status} - ${statusText}`); | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters