mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-28 07:24:36 +08:00
fix(tasks): Properly handle DraftNotFoundError in DestroyDraftTask
- Fix reference to actual DestroyDraftTask class inside syncback-draft-task
This commit is contained in:
parent
419eace7e8
commit
a6f9e84c9a
3 changed files with 8 additions and 14 deletions
|
@ -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'
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))) {
|
||||
|
|
Loading…
Add table
Reference in a new issue