Skip to content

Commit

Permalink
Move check from postConnect to checkConnection (#256)
Browse files Browse the repository at this point in the history
* Move check from postConnect to checkConnection

* Throw error so we prevent creating the connection if check fails

---------

Co-authored-by: Rodrigo Arze Leon <[email protected]>
  • Loading branch information
Rodri77 and Rodrigo Arze Leon authored Feb 12, 2025
1 parent cbc1fce commit 0cb5287
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions connectors/connector-aircall/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export const aircallServer = {
})
return aircall
},
postConnect: async (connectOutput, _, context) => {
checkConnection: async ({settings}) => {
// Encoding credentials:
const apiId = context.connection?.settings.apiId
const apiToken = context.connection?.settings.apiToken
const apiId = settings.apiId
const apiToken = settings.apiToken
const encodedCredentials = Buffer.from(`${apiId}:${apiToken}`).toString(
'base64',
)
Expand All @@ -44,17 +44,18 @@ export const aircallServer = {
console.error(
`HTTP error! status: ${response.status} - ${response.statusText}`,
)
throw new Error('Invalid Aircall credentials')
}

const body = await response.text()
console.log('Response from Aircall Ping:', body)
} catch (error) {
console.error('Error during fetch:', error)
throw error
}

return {
connectionExternalId: connectOutput.connectionId,
providerConfigKey: connectOutput.providerConfigKey,
connectionExternalId: settings.apiId,
}
},
} satisfies ConnectorServer<
Expand Down

0 comments on commit 0cb5287

Please sign in to comment.