Skip to content

Commit

Permalink
Add hasError flag to throw even falsy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Mar 15, 2022
1 parent 5082a34 commit 761c82b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,9 @@ Action triggered to delete an entity record.

_Parameters_

- _kind_ `string`: Kind of the deleted entity record.
- _name_ `string`: Name of the deleted entity record.
- _recordId_ `string`: Record ID of the deleted entity record.
- _kind_ `string`: Kind of the deleted entity.
- _name_ `string`: Name of the deleted entity.
- _recordId_ `string`: Record ID of the deleted entity.
- _query_ `?Object`: Special query parameters for the DELETE API call.
- _options_ `[Object]`: Delete options.
- _options.\_\_unstableFetch_ `[Function]`: Internal use only. Function to call instead of `apiFetch()`. Must return a promise.
Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ Action triggered to delete an entity record.

_Parameters_

- _kind_ `string`: Kind of the deleted entity record.
- _name_ `string`: Name of the deleted entity record.
- _recordId_ `string`: Record ID of the deleted entity record.
- _kind_ `string`: Kind of the deleted entity.
- _name_ `string`: Name of the deleted entity.
- _recordId_ `string`: Record ID of the deleted entity.
- _query_ `?Object`: Special query parameters for the DELETE API call.
- _options_ `[Object]`: Delete options.
- _options.\_\_unstableFetch_ `[Function]`: Internal use only. Function to call instead of `apiFetch()`. Must return a promise.
Expand Down
8 changes: 6 additions & 2 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export const deleteEntityRecord = (
recordId,
} );

let hasError = false;
try {
let path = `${ entityConfig.baseURL }/${ recordId }`;

Expand All @@ -264,6 +265,7 @@ export const deleteEntityRecord = (

await dispatch( removeItems( kind, name, recordId, true ) );
} catch ( _error ) {
hasError = true;
error = _error;
}

Expand All @@ -275,7 +277,7 @@ export const deleteEntityRecord = (
error,
} );

if ( error && throwOnError ) {
if ( hasError && throwOnError ) {
throw error;
}

Expand Down Expand Up @@ -457,6 +459,7 @@ export const saveEntityRecord = (
} );
let updatedRecord;
let error;
let hasError = false;
try {
const path = `${ entityConfig.baseURL }${
recordId ? '/' + recordId : ''
Expand Down Expand Up @@ -579,6 +582,7 @@ export const saveEntityRecord = (
);
}
} catch ( _error ) {
hasError = true;
error = _error;
}
dispatch( {
Expand All @@ -590,7 +594,7 @@ export const saveEntityRecord = (
isAutosave,
} );

if ( error && throwOnError ) {
if ( hasError && throwOnError ) {
throw error;
}

Expand Down

0 comments on commit 761c82b

Please sign in to comment.