Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

logflare-transport-core

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logflare-transport-core - npm Package Compare versions

Comparing version 0.3.0-3f3ffeaf to 0.3.0-4c8220fd

.github/workflows/tests.yml

2

package.json
{
"name": "logflare-transport-core",
"version": "0.3.0-3f3ffeaf",
"version": "0.3.0-4c8220fd",
"description": "A common core for Logflare javascript transports.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -12,2 +12,10 @@ interface IngestTransformsI {

fromBrowser?: boolean
onError?:
| ((
payload: {
batch: object[]
},
err: Error
) => void)
| undefined
}

@@ -38,2 +46,13 @@

protected readonly apiBaseUrl: string
/**
* onError takes in an optional callback function to handle any errors returned by logflare
*/
protected readonly onError?:
| ((
payload: {
batch: object[]
},
err: Error
) => void)
| undefined

@@ -54,2 +73,3 @@ public constructor(options: LogflareUserOptionsI) {

this.apiBaseUrl = options.apiBaseUrl || defaultOptions.apiBaseUrl
this.onError = options.onError
}

@@ -96,3 +116,3 @@

} catch (e) {
if (e) {
if (e && e instanceof Error) {
if (e instanceof NetworkError && e.response) {

@@ -104,5 +124,6 @@ console.error(

)
} else if (e instanceof Error) {
} else {
console.error(e.message)
}
this.onError?.(payload, e)
}

@@ -109,0 +130,0 @@

@@ -10,6 +10,14 @@ import {LogflareHttpClient} from "./main"

let httpClient
let httpClientOnError
let nativeFetch
let consoleErrorData = []
const storeLog = (inputs) => consoleErrorData.push(inputs)
const onErrorCallback = jest.fn((payload, err) => {
console.error(payload)
console.error(err)
})
beforeAll(() => {
nativeFetch = global.fetch
console["error"] = jest.fn(storeLog)
})

@@ -23,2 +31,8 @@

})
httpClientOnError = new LogflareHttpClient({
apiKey: testApiKey,
sourceToken: testSourceToken,
apiBaseUrl: "http://non-existing.domain",
onError: onErrorCallback,
})
})

@@ -28,2 +42,3 @@

global.fetch.mockClear()
consoleErrorData = []
})

@@ -61,8 +76,5 @@

let consoleLogData = ""
const storeLog = (inputs) => (consoleLogData += inputs)
it("prints to console on error", async () => {
const errorResponse = {message: "Schema validation error"}
console["error"] = jest.fn(storeLog)
global.fetch = jest.fn(() =>

@@ -79,3 +91,3 @@ Promise.resolve({

await httpClient.addLogEvent(le)
expect(consoleLogData).toBe(
expect(consoleErrorData[0]).toBe(
`Logflare API request failed with 406 status: ${JSON.stringify(

@@ -86,2 +98,30 @@ errorResponse

})
it("invoke onError callback on error", async () => {
const errorResponse = {message: "Schema validation error"}
global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve(errorResponse),
ok: false,
status: 406,
})
)
const le = {message: "info log msg", metadata: {p1: "v1"}}
await httpClientOnError.addLogEvent(le)
const [message, payload, err] = consoleErrorData
expect(message).toBe(
`Logflare API request failed with 406 status: ${JSON.stringify(
errorResponse
)}`
)
expect(onErrorCallback).toHaveBeenCalledTimes(1)
expect(payload).toStrictEqual({
batch: [le],
})
expect(err.message).toMatch(/Network response was not ok for/)
expect(err.data).toBe(errorResponse)
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc