How to use serialize-error - 10 common examples

To help you get started, we’ve selected a few serialize-error examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gajus / slonik / src / sqlFragmentFactories / createJsonSqlFragment.js View on Github external
if (token.value === undefined) {
    throw new InvalidInputError('JSON payload must not be undefined.');
  } else if (token.value === null) {
    value = token.value;

  // @todo Deep check Array.
  // eslint-disable-next-line no-negated-condition
  } else if (!isPlainObject(token.value) && !Array.isArray(token.value)) {
    throw new InvalidInputError('JSON payload must be a primitive value or a plain object.');
  } else {
    try {
      value = JSON.stringify(token.value);
    } catch (error) {
      log.error({
        error: serializeError(error),
      }, 'payload cannot be stringified');

      throw new InvalidInputError('JSON payload cannot be stringified.');
    }

    if (value === undefined) {
      throw new InvalidInputError('JSON payload cannot be stringified. The resulting value is undefined.');
    }
  }

  // Do not add `::json` as it will fail if an attempt is made to insert to jsonb-type column.
  return {
    sql: '$' + (greatestParameterPosition + 1),
    values: [
      value,
    ],
github ImmoweltGroup / create-react-microservice / packages / create-react-microservice-scaffold / src / packages / my-fancy-ui / src / app.js View on Github external
//
    // We wrap the server side state generation inside a try/catch to have the ability to fall back to an
    // server AND client saga behavior if the state generation failed.
    //
    try {
      const {store, rootSagaInstance} = createStoreContext({
        reduxSagaContext: 'server'
      });

      await rootSagaInstance.done;

      initialState = store.getState();
    } catch (e) {
      reduxSagaContext = 'universal';
      errors.push(serialize(e));
    }

    return {
      query,
      reduxSagaContext,
      errors,
      initialState
    };
  }
github swagger-api / swagger-ui / src / core / system.js View on Github external
return ( ...args )=>{
        var action = null
        try{
          action = creator( ...args )
        }
        catch( e ){
          action = {type: NEW_THROWN_ERR, error: true, payload: serializeError(e) }
        }
        finally{
          return action // eslint-disable-line no-unsafe-finally
        }
      }
github teambit / bit / src / specs-runner / specs-runner.js View on Github external
function deserializeResults(results): ?SpecsResultsWithMetaData {
  if (!results) return undefined;
  if (results.type === 'error') {
    let deserializedError = deserializeError(results.error);
    // Special desrialization for external errors
    if (deserializedError.originalErrors) {
      const deserializedOriginalErrors = deserializedError.originalErrors.map(deserializeError);
      if (results.error.name === ExternalBuildErrors.name) {
        deserializedError = new ExternalBuildErrors(deserializedError.id, deserializedOriginalErrors);
      } else if (results.error.name === ExternalTestErrors.name) {
        deserializedError = new ExternalTestErrors(deserializedError.id, deserializedOriginalErrors);
      } else {
        deserializedError = new ExternalErrors(deserializedOriginalErrors);
      }
    }
    if (deserializedError.originalError) {
      const deserializedOriginalError = deserializeError(deserializedError.originalError);
      const compName =
        deserializedError.compName && typeof deserializedError.compName === 'string' ? deserializedError.compName : '';
      deserializedError = new ExternalTestErrors(compName, [deserializedOriginalError]);
github teambit / bit / src / specs-runner / specs-runner.ts View on Github external
function deserializeResults(results): SpecsResultsWithMetaData | null | undefined {
  if (!results) return undefined;
  if (results.type === 'error') {
    let deserializedError = deserializeError(results.error);
    // Special desrialization for external errors
    // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
    if (deserializedError.originalErrors) {
      // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
      const deserializedOriginalErrors = deserializedError.originalErrors.map(deserializeError);
      if (results.error.name === ExternalBuildErrors.name) {
        // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
        deserializedError = new ExternalBuildErrors(deserializedError.id, deserializedOriginalErrors);
      } else if (results.error.name === ExternalTestErrors.name) {
        // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
        deserializedError = new ExternalTestErrors(deserializedError.id, deserializedOriginalErrors);
      } else {
        deserializedError = new ExternalErrors(deserializedOriginalErrors);
      }
    }
    // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
github teambit / bit / src / specs-runner / specs-runner.ts View on Github external
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
      const deserializedOriginalErrors = deserializedError.originalErrors.map(deserializeError);
      if (results.error.name === ExternalBuildErrors.name) {
        // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
        deserializedError = new ExternalBuildErrors(deserializedError.id, deserializedOriginalErrors);
      } else if (results.error.name === ExternalTestErrors.name) {
        // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
        deserializedError = new ExternalTestErrors(deserializedError.id, deserializedOriginalErrors);
      } else {
        deserializedError = new ExternalErrors(deserializedOriginalErrors);
      }
    }
    // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
    if (deserializedError.originalError) {
      // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
      const deserializedOriginalError = deserializeError(deserializedError.originalError);
      const compName =
        // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
        // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
        // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
        deserializedError.compName && typeof deserializedError.compName === 'string' ? deserializedError.compName : '';
      deserializedError = new ExternalTestErrors(compName, [deserializedOriginalError]);
    }
    const finalResults = {
      type: 'error',
      error: deserializedError
    };
    // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
    return finalResults;
  }
  const deserializeFailure = failure => {
    if (!failure) return undefined;
github teambit / bit / src / specs-runner / specs-runner.js View on Github external
if (!results) return undefined;
  if (results.type === 'error') {
    let deserializedError = deserializeError(results.error);
    // Special desrialization for external errors
    if (deserializedError.originalErrors) {
      const deserializedOriginalErrors = deserializedError.originalErrors.map(deserializeError);
      if (results.error.name === ExternalBuildErrors.name) {
        deserializedError = new ExternalBuildErrors(deserializedError.id, deserializedOriginalErrors);
      } else if (results.error.name === ExternalTestErrors.name) {
        deserializedError = new ExternalTestErrors(deserializedError.id, deserializedOriginalErrors);
      } else {
        deserializedError = new ExternalErrors(deserializedOriginalErrors);
      }
    }
    if (deserializedError.originalError) {
      const deserializedOriginalError = deserializeError(deserializedError.originalError);
      const compName =
        deserializedError.compName && typeof deserializedError.compName === 'string' ? deserializedError.compName : '';
      deserializedError = new ExternalTestErrors(compName, [deserializedOriginalError]);
    }
    const finalResults = {
      type: 'error',
      error: deserializedError
    };
    return finalResults;
  }
  const deserializeFailure = (failure) => {
    if (!failure) return undefined;
    const deserializedFailure = failure;
    if (failure.err) {
      try {
        deserializedFailure.err = deserializeError(failure.err);
github SocialXNetwork / socialx_react_native / packages / webview-crypto / src / MainWorker.ts View on Github external
.then(({ id, value, reason }) => {
				if (this.debug) {
					console.log(
						'[webview-crypto] Received message:',
						JSON.stringify({
							id,
							value,
							reason,
						}),
					);
				}
				if (!id) {
					console.warn(
						'[webview-crypto] no ID passed back from message:',
						JSON.stringify(serializeError(reason)),
					);
					return;
				}
				const { resolve, reject } = this.messages[id];
				if (value) {
					resolve(value);
				} else {
					reject(reason);
				}
				delete this.messages[id];
			})
			.catch((reason) => {
github gimkit / blueboat / src / lib / server / Connection / ConnectionHandler.ts View on Github external
pubsub,
          socket,
          storage,
          availableRoomTypes,
          onRoomDisposed,
          request.type,
          await roomFetcher.getListOfRooms(),
          request.options,
          customRoomIdGenerator
        )
        Logger(`${room.roomId} made`, LoggerTypes.room)
        onRoomMade(room)

        socket.emit(`${request.uniqueRequestId}-create`, room.roomId)
      } catch (e) {
        const error = serializeError(e)
        Logger(
          `${socket.id} error creating room - ${JSON.stringify(error)}`,
          LoggerTypes.room
        )
        socket.emit(`${request.uniqueRequestId}-error`, error)
      }
    }
  )
github teambit / bit / src / logger / logger.js View on Github external
function addBreakCrumb(category: string, message: string, data: Object = {}, extraData) {
  const hashedData = {};
  Object.keys(data).forEach(key => (hashedData[key] = Analytics.hashData(data[key])));
  const messageWithHashedData = format(message, hashedData);
  extraData = extraData instanceof Error ? serializeError(extraData) : extraData;
  Analytics.addBreadCrumb(category, messageWithHashedData, extraData);
}

serialize-error

Serialize/deserialize an error into a plain object

MIT
Latest version published 1 year ago

Package Health Score

78 / 100
Full package analysis