forked from BrasilAPI/BrasilAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rejection to UF search promises when an empty list is returned
Prevents responses from providers that respond first, but with empty results, from being considered as the final result fix BrasilAPI#600
- Loading branch information
1 parent
324fcfd
commit f1864cf
Showing
2 changed files
with
17 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Rejects the promise if the data is an empty array. | ||
* | ||
* @param {Promise} promise | ||
* @returns {Promise} | ||
*/ | ||
export async function rejectWhenEmptyArray(promise) { | ||
const data = await promise; | ||
if (!data || data.length === 0) { | ||
throw new Error('Empty data'); | ||
} | ||
return data; | ||
} |