Skip to content

Commit

Permalink
ignore empty endpoints
Browse files Browse the repository at this point in the history
And don't throw when the request is failing
  • Loading branch information
simonabadoiu committed Nov 15, 2023
1 parent cd7a2cd commit dab74a0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Manager, MCEvent } from '@managed-components/types'
import { flattenKeys } from './utils'

function handleEvents(manager: Manager, event: MCEvent) {
if (!event.payload.endpoint) return
if (event.payload.method && event.payload.method.startsWith('post')) {
sendPostRequest(manager, event)
} else {
Expand All @@ -21,13 +22,15 @@ export function createRequestBody(event: MCEvent) {
}

export function sendPostRequest(manager: Manager, event: MCEvent) {
manager.fetch(`${event.payload.endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(createRequestBody(event)),
})
try {
manager.fetch(`${event.payload.endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(createRequestBody(event)),
})
} catch {}

Check failure on line 33 in src/index.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Empty block statement
}

// Functions related to get requests
Expand All @@ -43,7 +46,9 @@ export function constructGetRequestUrl(event: MCEvent) {
}

export function sendGetRequest(manager: Manager, event: MCEvent) {
manager.fetch(`${constructGetRequestUrl(event)}`)
try {
manager.fetch(`${constructGetRequestUrl(event)}`)
} catch {}

Check failure on line 51 in src/index.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Empty block statement
}

// Event listeners
Expand Down

0 comments on commit dab74a0

Please sign in to comment.