Skip to content

Commit

Permalink
fix error documents
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Jul 11, 2024
1 parent 84195b9 commit b4c319d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
7 changes: 3 additions & 4 deletions packages/store/src/-private/cache-handler/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
import type { ApiError } from '@warp-drive/core-types/spec/error';
import type { ResourceIdentifierObject } from '@warp-drive/core-types/spec/json-api-raw';

import type { OpaqueRecordInstance } from '../../-types/q/record-instance';
import { Document } from '../document';
import type { Store } from '../store-service';
import {
Expand Down Expand Up @@ -246,11 +245,11 @@ function maybeUpdateErrorUiObjects<T>(
): ResourceErrorDocument {
const { identifier } = options;

assert(`Expected an error document`, isErrorDocument(document));

if (!identifier && !options.shouldHydrate) {
// TODO investigate why ResourceErrorDocument is insufficient for expressing all error types
if (!isErrorDocument(document) || (!identifier && !options.shouldHydrate)) {
return document;
}

let doc: Document<T> | undefined;
if (identifier) {
doc = store._documentCache.get(identifier) as Document<T> | undefined;
Expand Down
7 changes: 4 additions & 3 deletions packages/store/src/-private/cache-handler/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier';
import type {
ImmutableCreateRequestOptions,
ImmutableDeleteRequestOptions,
ImmutableRequestInfo,
ImmutableUpdateRequestOptions,
StructuredDataDocument,
} from '@warp-drive/core-types/request';
import type { Store } from '../store-service';
import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier';
import type { ApiError } from '@warp-drive/core-types/spec/error';
import type { ResourceDataDocument, ResourceErrorDocument } from '@warp-drive/core-types/spec/document';
import type { ApiError } from '@warp-drive/core-types/spec/error';

import type { Store } from '../store-service';

export const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);

Expand Down
2 changes: 1 addition & 1 deletion packages/store/src/-private/store-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import type { OpaqueRecordInstance } from '../-types/q/record-instance';
import type { SchemaService } from '../-types/q/schema-service';
import type { FindAllOptions, FindRecordOptions, LegacyResourceQuery, QueryOptions } from '../-types/q/store';
import type { StoreRequestInput } from './cache-handler/handler';
import type { CachePolicy } from './cache-handler/types';
import { IdentifierCache } from './caches/identifier-cache';
import {
InstanceCache,
Expand All @@ -60,7 +61,6 @@ import type { Collection, IdentifierArray } from './record-arrays/identifier-arr
import { coerceId, ensureStringId } from './utils/coerce-id';
import { constructResource } from './utils/construct-resource';
import { normalizeModelName } from './utils/normalize-model-name';
import type { CachePolicy } from './cache-handler/types';

export { storeFor };

Expand Down

0 comments on commit b4c319d

Please sign in to comment.