How to use the @vtex/api.ResolverError function in @vtex/api

To help you get started, we’ve selected a few @vtex/api 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 vtex-apps / store-graphql / node / resolvers / fileManager / client.ts View on Github external
try {
      const { filename, encoding, mimetype } = file
      const headers = {
        'Content-Type': mimetype,
        'Content-Encoding': encoding,
      }
      return await this.http.put(
        routes.FileUpload(bucket, filename),
        stream,
        {
          headers,
        }
      )
    } catch (e) {
      const status = e.statusCode || path(['response', 'status'], e) || 500
      throw new ResolverError(e, status)
    }
  }
github vtex-apps / store-graphql / node / directives / withCurrentProfile.ts View on Github external
return sessionQueries.getSession(null, null, context).then(currentSession => {
    const session = currentSession as SessionFields

    if (!session || !session.id) {
      throw new ResolverError('Error fetching session data')
    }

    const profile =
      session.impersonate && session.impersonate.profile
        ? session.impersonate.profile
        : session.profile

    return profile
      ? ({
          email: profile && profile.email,
          userId: profile && profile.id,
        } as CurrentProfile)
      : null
  })
}
github vtex-apps / store-graphql / node / resolvers / fileManager / client.ts View on Github external
public constructor(ioContext: IOContext, options: InstanceOptions = {}) {
    super('vtex.file-manager', ioContext, { ...options, timeout: 5000 })

    if (runningAppName === '') {
      throw new ResolverError(
        `Invalid path to access FileManger. Variable VTEX_APP_ID is not available.`
      )
    }
  }
github vtex-apps / store-graphql / node / resolvers / document / attachment.ts View on Github external
formData.append(field, buffer, {
    contentType: mimetype,
    filename: randomName,
    knownLength: buffer.byteLength,
  })

  const response = await masterdata.uploadAttachment(
    acronym,
    documentId,
    field,
    formData
  )

  if (response) {
    throw new ResolverError(response)
  }

  return { filename: randomName, mimetype }
}