Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
fix: prevent error message on notification without url
Browse files Browse the repository at this point in the history
  • Loading branch information
moranje committed Oct 14, 2018
1 parent 40845c1 commit 40d821a
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/workflow/notifier.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { AlfredError } from '@/workflow/error'
import omit from 'lodash.omit'
import notifier from 'node-notifier'
import open from 'opn'
import osName from 'os-name'
import compose from 'stampit'

import { AlfredError } from './error'

const NOTIFICATION_DEFAULTS = {
title: 'ALFRED WORKFLOW TODOIST',
subtitle: '✓ Happy days!',
message: "There's nothing to say.",
sound: false,
icon: `${process.cwd()}/icon.png`,
contentImage: '',
open: '',
open: void 0,
wait: void 0,
timeout: 5,
closeLabel: void 0,
Expand Down Expand Up @@ -41,6 +40,26 @@ export interface NotificationOptions {
error?: AlfredError
}

// function logError(error: AlfredError) {
// console.log('Something went wrong\n')
// console.log(
// [
// `${chalk.red(error.name)}: ${error.message}\n`,
// 'ALFRED WORKFLOW TODOIST',
// '----------------------------------------',
// `${chalk.green('os:')} ${osName()}`,
// `${chalk.green('query:')} ${error.QUERY}`,
// `${chalk.green('node.js:')} ${error.NODE_VERSION}`,
// `${chalk.green('alfred:')} ${error.ALFRED_VERSION}`,
// `${chalk.green('workflow:')} ${error.WORKFLOW_VERSION}`,
// `${chalk.green('Stack:')} ${error.stack}`
// ]
// .join('\n')
// // Hide token from log by default
// .replace(/[0-9a-fA-F]{40}/gm, chalk.blue('<token hidden>'))
// )
// }

function logError(error: AlfredError) {
console.log(
[
Expand All @@ -56,7 +75,7 @@ function logError(error: AlfredError) {
]
.join('\n')
// Hide token from log by default
.replace(/[0-9a-fA-F]{40}/gm, '<token>')
.replace(/[0-9a-fA-F]{40}/gm, '<token hidden>')
)
}

Expand All @@ -76,14 +95,13 @@ function notification(
notifier.notify(omit(options, ['error']), (err, response) => {
// Response is response from notification
if (err) {
console.log('Something went wrong\n', err)
logError(new AlfredError(err.name, err.message, err.stack))
}

if (options.error) {
console.log('Something went wrong\n')
logError(options.error)
}
// if (options.error) {
// console.log('Something went wrong\n', options.error)
// logError(options.error)
// }
})

notifier.on('click', onClick || onClickFallback)
Expand Down Expand Up @@ -117,7 +135,7 @@ export const Notification = compose({

methods: {
write(this: NotificationOptions, onClick?: any, onTimeout?: any) {
// if (this.error) logError(this.error)
if (this.error) logError(this.error)

notification(this, onClick, onTimeout)
}
Expand Down

0 comments on commit 40d821a

Please sign in to comment.