UNPKG

@envelop/core

Version:

This is the core package for Envelop. You can find a complete documentation here: https://github.com/n1ru4l/envelop

26 lines (25 loc) 788 B
import { handleStreamOrSingleExecutionResult } from '../utils.js'; const makeHandleResult = (errorHandler) => ({ result, args }) => { if (result.errors?.length) { errorHandler(result.errors, args); } }; export const useErrorHandler = (errorHandler) => { const handleResult = makeHandleResult(errorHandler); return { onExecute() { return { onExecuteDone(payload) { return handleStreamOrSingleExecutionResult(payload, handleResult); }, }; }, onSubscribe() { return { onSubscribeResult(payload) { return handleStreamOrSingleExecutionResult(payload, handleResult); }, }; }, }; };