How to use the netlify-cms-lib-util.APIError function in netlify-cms-lib-util

To help you get started, we’ve selected a few netlify-cms-lib-util 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 netlify / netlify-cms / packages / netlify-cms-backend-git-gateway / src / GitHubAPI.js View on Github external
.catch(error => {
        if (error.status === 401) {
          if (error.message === 'Bad credentials') {
            throw new APIError(
              'Git Gateway Error: Please ask your site administrator to reissue the Git Gateway token.',
              error.status,
              'Git Gateway',
            );
          } else {
            return false;
          }
        } else if (
          error.status === 404 &&
          (error.message === undefined || error.message === 'Unable to locate site configuration')
        ) {
          throw new APIError(
            `Git Gateway Error: Please make sure Git Gateway is enabled on your site.`,
            error.status,
            'Git Gateway',
          );
        } else {
          console.error('Problem fetching repo data from Git Gateway');
          throw error;
        }
      });
  }
github netlify / netlify-cms / packages / netlify-cms-backend-github / src / GraphQLAPI.js View on Github external
const { nodes } = data.repository.refs;
    if (nodes.length > 0) {
      const branches = [];
      nodes.forEach(({ associatedPullRequests }) => {
        associatedPullRequests.nodes.forEach(({ headRef }) => {
          branches.push({ ref: `${headRef.prefix}${headRef.name}` });
        });
      });

      return await Promise.all(branches.map(branch => this.migrateBranch(branch)));
    } else {
      console.log(
        '%c No Unpublished entries',
        'line-height: 30px;text-align: center;font-weight: bold',
      );
      throw new APIError('Not Found', 404, 'GitHub');
    }
  }
github netlify / netlify-cms / packages / netlify-cms-backend-github / src / GraphQLAPI.js View on Github external
async retrieveContent({ path, branch, repoURL, parseText }) {
    const { owner, name } = this.getOwnerAndNameFromRepoUrl(repoURL);
    const { is_null, is_binary, text } = await this.retrieveBlobObject(
      owner,
      name,
      `${branch}:${path}`,
    );
    if (is_null) {
      throw new APIError('Not Found', 404, 'GitHub');
    } else if (!is_binary) {
      return text;
    } else {
      return super.retrieveContent({ path, branch, repoURL, parseText });
    }
  }
github netlify / netlify-cms / packages / netlify-cms-backend-git-gateway / src / GitHubAPI.js View on Github external
.catch(error => {
        if (error.status === 401) {
          if (error.message === 'Bad credentials') {
            throw new APIError(
              'Git Gateway Error: Please ask your site administrator to reissue the Git Gateway token.',
              error.status,
              'Git Gateway',
            );
          } else {
            return false;
          }
        } else if (
          error.status === 404 &&
          (error.message === undefined || error.message === 'Unable to locate site configuration')
        ) {
          throw new APIError(
            `Git Gateway Error: Please make sure Git Gateway is enabled on your site.`,
            error.status,
            'Git Gateway',
          );
github netlify / netlify-cms / packages / netlify-cms-backend-git-gateway / src / GitHubAPI.js View on Github external
handleRequestError(error, responseStatus) {
    throw new APIError(error.message || error.msg, responseStatus, 'Git Gateway');
  }
github netlify / netlify-cms / packages / netlify-cms-backend-github / src / GraphQLAPI.js View on Github external
return this.client.query(options).catch(error => {
      throw new APIError(error.message, 500, 'GitHub');
    });
  }
github netlify / netlify-cms / packages / netlify-cms-backend-bitbucket / src / API.js View on Github external
      p => p.catch(err => Promise.reject(new APIError(err.message, null, 'BitBucket'))),
    ])(req);
github netlify / netlify-cms / packages / netlify-cms-backend-gitlab / src / API.js View on Github external
      p => p.catch(err => Promise.reject(new APIError(err.message, null, 'GitLab'))),
    ])(req);
github netlify / netlify-cms / packages / netlify-cms-backend-gitlab / src / API.js View on Github external
parseResponse = async (res, { expectingOk = true, expectingFormat = 'text' }) => {
    let body;
    try {
      const formatter = this.responseFormats.get(expectingFormat, false);
      if (!formatter) {
        throw new Error(`${expectingFormat} is not a supported response format.`);
      }
      body = await formatter(res);
    } catch (err) {
      throw new APIError(err.message, res.status, 'GitLab');
    }
    if (expectingOk && !res.ok) {
      const isJSON = expectingFormat === 'json';
      throw new APIError(isJSON && body.message ? body.message : body, res.status, 'GitLab');
    }
    return body;
  };
github netlify / netlify-cms / packages / netlify-cms-backend-github / src / GraphQLAPI.js View on Github external
async listFiles(path, { repoURL = this.repoURL, branch = this.branch, depth = 1 } = {}) {
    const { owner, name } = this.getOwnerAndNameFromRepoUrl(repoURL);
    const { data } = await this.query({
      query: queries.files(depth),
      variables: { owner, name, expression: `${branch}:${path}` },
    });

    if (data.repository.object) {
      const allFiles = this.getAllFiles(data.repository.object.entries, path);
      return allFiles;
    } else {
      throw new APIError('Not Found', 404, 'GitHub');
    }
  }