fix(tasks): Properly handle DraftNotFoundError in DestroyDraftTask

- Fix reference to actual DestroyDraftTask class inside
  syncback-draft-task
This commit is contained in:
Juan Tejada 2016-03-22 14:34:09 -07:00
parent 419eace7e8
commit a6f9e84c9a
3 changed files with 8 additions and 14 deletions

View file

@ -1,6 +1,6 @@
React = require "react"
{RetinaImg} = require 'nylas-component-kit'
{Actions, FocusedContentStore, DestroyDraftTask} = require "nylas-exports"
{Actions, FocusedContentStore} = require "nylas-exports"
class DraftDeleteButton extends React.Component
@displayName: 'DraftDeleteButton'

View file

@ -17,20 +17,17 @@ export default class DestroyDraftTask extends BaseDraftTask {
performLocal() {
super.performLocal();
return this.refreshDraftReference().then(()=>
DatabaseStore.inTransaction((t) =>
t.unpersistModel(this.draft)
)
);
return this.refreshDraftReference()
.then(() => DatabaseStore.inTransaction((t) => t.unpersistModel(this.draft)))
.catch(BaseDraftTask.DraftNotFoundError, () => Promise.resolve());
}
performRemote() {
// We don't need to do anything if (we weren't able to find the draft)
// when we performed locally, or if (the draft has never been synced to)
// We don't need to do anything if we weren't able to find the draft
// when we performed locally, or if the draft has never been synced to
// the server (id is still self-assigned)
if (!this.draft) {
const err = new Error("No valid draft to destroy!");
return Promise.resolve([Task.Status.Failed, err]);
return Promise.resolve(Task.Status.Continue);
}
if (!this.draft.serverId) {
return Promise.resolve(Task.Status.Continue);

View file

@ -7,9 +7,6 @@ import BaseDraftTask from './base-draft-task';
import SyncbackMetadataTask from './syncback-metadata-task';
import {APIError} from '../errors';
class DraftNotFoundError extends Error {
}
export default class SyncbackDraftTask extends BaseDraftTask {
@ -27,7 +24,7 @@ export default class SyncbackDraftTask extends BaseDraftTask {
.thenReturn(Task.Status.Success)
)
.catch((err) => {
if (err instanceof DraftNotFoundError) {
if (err instanceof BaseDraftTask.DraftNotFoundError) {
return Promise.resolve(Task.Status.Continue);
}
if ((err instanceof APIError) && (!NylasAPI.PermanentErrorCodes.includes(err.statusCode))) {