import { isErrorInfo, sendErrorToService } from "Utils/errors"

export const shouldCaptureError = (environment: string) =>
  environment === "staging" || environment === "production"

export default function createLogger(namespace = "reaction") {
  const formattedNamespace = `${namespace} |`

  return {
    log: (...messages) => {
      console.log(formattedNamespace, ...messages, "\n")
    },
    warn: (...warnings) => {
      console.warn(formattedNamespace, ...warnings, "\n")
    },
    error: (...errors) => {
      const error = errors.find(e => e instanceof Error)
      const errorInfo = errors.find(isErrorInfo)

      if (error && shouldCaptureError(process.env.NODE_ENV)) {
        sendErrorToService(error, errorInfo)
      }

      console.error(formattedNamespace, ...errors, "\n")
    },
  }
}

import { head } from "lodash"
import { isErrorInfo, sendErrorToService } from "Utils/errors"

export const shouldCaptureError = (environment: string) =>
  environment === "staging" || environment === "production"

export default function createLogger(namespace = "reaction") {
  const formattedNamespace = `${namespace} |`

  return {
    log: (...messages) => {
      console.log(formattedNamespace, ...messages, "\n")
    },
    warn: (...warnings) => {
      console.warn(formattedNamespace, ...warnings, "\n")
    },
    error: (...errors) => {
      const error = head(errors.filter(e => e instanceof Error))
      const errorInfo = head(errors.filter(e => isErrorInfo(e)))

      if (error && shouldCaptureError(process.env.NODE_ENV)) {
        sendErrorToService(error, errorInfo)
      }

      console.error(formattedNamespace, ...errors, "\n")
    },
  }
}

--- 
+++ 
@@ -1,4 +1,3 @@
-import { head } from "lodash"
 import { isErrorInfo, sendErrorToService } from "Utils/errors"
 
 export const shouldCaptureError = (environment: string) =>
@@ -15,8 +14,8 @@
       console.warn(formattedNamespace, ...warnings, "\n")
     },
     error: (...errors) => {
-      const error = head(errors.filter(e => e instanceof Error))
-      const errorInfo = head(errors.filter(e => isErrorInfo(e)))
+      const error = errors.find(e => e instanceof Error)
+      const errorInfo = errors.find(isErrorInfo)
 
       if (error && shouldCaptureError(process.env.NODE_ENV)) {
         sendErrorToService(error, errorInfo)
Use Array.find when searching for errors and errorInfO
