move errors to utils lib

This commit is contained in:
Shawn Erquhart 2018-07-16 23:08:16 -04:00
parent 4931711892
commit e491f2a085
10 changed files with 17 additions and 15 deletions

View File

@ -6,7 +6,7 @@ import { currentBackend } from 'Backends/backend';
import { getAsset } from 'Reducers';
import { selectFields } from 'Reducers/collections';
import { status, EDITORIAL_WORKFLOW } from 'Constants/publishModes';
import { EditorialWorkflowError } from "ValueObjects/errors";
import EditorialWorkflowError from 'netlify-cms-lib-util/EditorialWorkflowError';
import { loadEntry } from './entries';
import ValidationErrorTypes from 'Constants/validationErrorTypes';

View File

@ -1,5 +1,5 @@
import GithubAPI from "Backends/github/API";
import { APIError } from "ValueObjects/errors";
import APIError from "netlify-cms-lib-util/APIError";
export default class API extends GithubAPI {
constructor(config) {

View File

@ -1,5 +1,5 @@
import GithubAPI from "Backends/github/API";
import { APIError } from "ValueObjects/errors";
import APIError from "netlify-cms-lib-util/APIError";
export default class API extends GithubAPI {
constructor(config) {

View File

@ -1,10 +1,10 @@
import localForage from "netlify-cms-lib-util/localForage";
import { Base64 } from "js-base64";
import { uniq, initial, last, get, find, hasIn } from "lodash";
import { uniq, initial, last, get, find, hasIn, partial } from "lodash";
import { filterPromises, resolvePromiseProperties } from "netlify-cms-lib-util/promise";
import AssetProxy from "ValueObjects/AssetProxy";
import { SIMPLE, EDITORIAL_WORKFLOW, status } from "Constants/publishModes";
import { APIError, EditorialWorkflowError } from "ValueObjects/errors";
import { APIError, EditorialWorkflowError } from "netlify-cms-lib-util";
const CMS_BRANCH_PREFIX = 'cms/';
@ -713,7 +713,7 @@ export default class API {
}
uploadBlob(item) {
const content = item instanceof AssetProxy ? item.toBase64() : this.toBase64(item.raw);
const content = get(item, 'toBase64', partial(this.toBase64, item.raw))();
return content.then(contentBase64 => this.request(`${ this.repoURL }/git/blobs`, {
method: "POST",

View File

@ -1,11 +1,11 @@
import localForage from "netlify-cms-lib-util/localForage";
import { Base64 } from "js-base64";
import { fromJS, List, Map } from "immutable";
import { cond, flow, isString, partial, partialRight, pick, omit, set, update } from "lodash";
import { cond, flow, isString, partial, partialRight, pick, omit, set, update, get } from "lodash";
import unsentRequest from "netlify-cms-lib-util/unsentRequest";
import { then } from "netlify-cms-lib-util/promise";
import APIError from "netlify-cms-lib-util/APIError";
import AssetProxy from "ValueObjects/AssetProxy";
import { APIError } from "ValueObjects/errors";
import Cursor from "ValueObjects/Cursor"
export default class API {
@ -17,8 +17,9 @@ export default class API {
this.repoURL = `/projects/${ encodeURIComponent(this.repo) }`;
}
withAuthorizationHeaders = req =>
unsentRequest.withHeaders(this.token ? { Authorization: `Bearer ${ this.token }` } : {}, req);
withAuthorizationHeaders = req => (
unsentRequest.withHeaders(this.token ? { Authorization: `Bearer ${ this.token }` } : {}, req)
);
buildRequest = req => flow([
unsentRequest.withRoot(this.api_root),
@ -189,7 +190,7 @@ export default class API {
toBase64 = str => Promise.resolve(Base64.encode(str));
fromBase64 = str => Base64.decode(str);
uploadAndCommit = async (item, { commitMessage, updateFile = false, branch = this.branch, author = this.commitAuthor }) => {
const content = await (item instanceof AssetProxy ? item.toBase64() : this.toBase64(item.raw));
const content = get(item, 'toBase64', partial(this.toBase64, item.raw))();
const file_path = item.path.replace(/^\//, "");
const action = (updateFile ? "update" : "create");
const encoding = "base64";

View File

@ -2,7 +2,7 @@ import { remove, attempt, isError, take } from 'lodash';
import uuid from 'uuid/v4';
import { fromJS } from 'immutable';
import { EDITORIAL_WORKFLOW, status } from 'Constants/publishModes';
import { EditorialWorkflowError } from 'ValueObjects/errors';
import EditorialWorkflowError from 'netlify-cms-lib-util/EditorialWorkflowError';
import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from 'ValueObjects/Cursor'
import AuthenticationPage from './AuthenticationPage';

View File

@ -1,3 +0,0 @@
export { default as APIError } from './APIError';
export { default as EditorialWorkflowError } from './EditorialWorkflowError';

View File

@ -2,6 +2,8 @@ import localForage from './localForage';
import { resolvePath, basename, fileExtensionWithSeparator, fileExtension } from './path';
import { filterPromises, resolvePromiseProperties, then } from './promise';
import unsentRequest from './unsentRequest';
import APIError from './APIError';
import EditorialWorkflowError from './EditorialWorkflowError';
export {
localForage,
@ -13,4 +15,6 @@ export {
resolvePromiseProperties,
then,
unsentRequest,
APIError,
EditorialWorkflowError,
};