diff --git a/src/services/error-log.ts b/src/services/error-log.ts new file mode 100644 index 00000000..f0d3b934 --- /dev/null +++ b/src/services/error-log.ts @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2020 The Pybricks Authors + +import { Action } from '../actions'; +import { BootloaderConnectionActionType } from '../actions/bootloader'; +import { combineServices } from '.'; + +async function consoleLog(action: Action): Promise { + switch (action.type) { + case BootloaderConnectionActionType.DidError: + console.error(action.err); + break; + } +} + +export default combineServices(consoleLog); diff --git a/src/services/index.ts b/src/services/index.ts index 73c52385..e17d3477 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -6,6 +6,7 @@ import { Action, Dispatch } from '../actions'; import { RootState } from '../reducers'; import bootloader from './bootloader'; import editor from './editor'; +import errorLog from './error-log'; type Service = (action: Action, dispatch: Dispatch, state: RootState) => Promise; @@ -27,7 +28,7 @@ export function combineServices(...services: Service[]): Service { }; } -const rootService = combineServices(bootloader, editor); +const rootService = combineServices(bootloader, editor, errorLog); const serviceMiddleware: Middleware = (store) => (next) => (action): unknown => { runService(rootService, action, store.dispatch, store.getState());