mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-03 01:44:42 +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"
|
React = require "react"
|
||||||
{RetinaImg} = require 'nylas-component-kit'
|
{RetinaImg} = require 'nylas-component-kit'
|
||||||
{Actions, FocusedContentStore, DestroyDraftTask} = require "nylas-exports"
|
{Actions, FocusedContentStore} = require "nylas-exports"
|
||||||
|
|
||||||
class DraftDeleteButton extends React.Component
|
class DraftDeleteButton extends React.Component
|
||||||
@displayName: 'DraftDeleteButton'
|
@displayName: 'DraftDeleteButton'
|
||||||
|
|
|
@ -17,20 +17,17 @@ export default class DestroyDraftTask extends BaseDraftTask {
|
||||||
|
|
||||||
performLocal() {
|
performLocal() {
|
||||||
super.performLocal();
|
super.performLocal();
|
||||||
return this.refreshDraftReference().then(()=>
|
return this.refreshDraftReference()
|
||||||
DatabaseStore.inTransaction((t) =>
|
.then(() => DatabaseStore.inTransaction((t) => t.unpersistModel(this.draft)))
|
||||||
t.unpersistModel(this.draft)
|
.catch(BaseDraftTask.DraftNotFoundError, () => Promise.resolve());
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
performRemote() {
|
performRemote() {
|
||||||
// We don't need to do anything if (we weren't able to find the draft)
|
// 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)
|
// when we performed locally, or if the draft has never been synced to
|
||||||
// the server (id is still self-assigned)
|
// the server (id is still self-assigned)
|
||||||
if (!this.draft) {
|
if (!this.draft) {
|
||||||
const err = new Error("No valid draft to destroy!");
|
return Promise.resolve(Task.Status.Continue);
|
||||||
return Promise.resolve([Task.Status.Failed, err]);
|
|
||||||
}
|
}
|
||||||
if (!this.draft.serverId) {
|
if (!this.draft.serverId) {
|
||||||
return Promise.resolve(Task.Status.Continue);
|
return Promise.resolve(Task.Status.Continue);
|
||||||
|
|
|
@ -7,9 +7,6 @@ import BaseDraftTask from './base-draft-task';
|
||||||
import SyncbackMetadataTask from './syncback-metadata-task';
|
import SyncbackMetadataTask from './syncback-metadata-task';
|
||||||
import {APIError} from '../errors';
|
import {APIError} from '../errors';
|
||||||
|
|
||||||
class DraftNotFoundError extends Error {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class SyncbackDraftTask extends BaseDraftTask {
|
export default class SyncbackDraftTask extends BaseDraftTask {
|
||||||
|
|
||||||
|
@ -27,7 +24,7 @@ export default class SyncbackDraftTask extends BaseDraftTask {
|
||||||
.thenReturn(Task.Status.Success)
|
.thenReturn(Task.Status.Success)
|
||||||
)
|
)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err instanceof DraftNotFoundError) {
|
if (err instanceof BaseDraftTask.DraftNotFoundError) {
|
||||||
return Promise.resolve(Task.Status.Continue);
|
return Promise.resolve(Task.Status.Continue);
|
||||||
}
|
}
|
||||||
if ((err instanceof APIError) && (!NylasAPI.PermanentErrorCodes.includes(err.statusCode))) {
|
if ((err instanceof APIError) && (!NylasAPI.PermanentErrorCodes.includes(err.statusCode))) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue