UNPKG

@iexec/dataprotector

Version:

This product enables users to confidentially store data–such as mail address, documents, personal information ...

60 lines (51 loc) 1.5 kB
import { ApiCallError } from 'iexec/errors'; import { ValidationError } from 'yup'; export const grantAccessErrorMessage = 'Failed to grant access'; export const consumeProtectedDataErrorMessage = 'Failed to consume protected data'; export const processProtectedDataErrorMessage = 'Failed to process protected data'; export const prepareBulkRequestErrorMessage = 'Failed to prepare bulk request'; export class WorkflowError extends Error { isProtocolError: boolean; constructor({ message, errorCause, isProtocolError = false, }: { message: string; errorCause: Error; isProtocolError?: boolean; }) { super(message, { cause: errorCause }); this.name = this.constructor.name; this.isProtocolError = isProtocolError; } } export function handleIfProtocolError(error: Error) { if (error instanceof ApiCallError) { throw new WorkflowError({ message: "A service in the iExec protocol appears to be unavailable. You can retry later or contact iExec's technical support for help.", errorCause: error, isProtocolError: true, }); } } export class ErrorWithData extends Error { data: Record<string, any>; originalError?: Error; constructor( message: string, data: Record<string, any>, originalError?: Error ) { super(message); this.name = this.constructor.name; this.data = data; if (originalError) { this.originalError = originalError; } } } export { ValidationError };