Skip to content

Conversation

@daveallie
Copy link
Collaborator

@daveallie daveallie commented Jan 23, 2025

Calling pick and then cancelling the picker on iOS will currently throw an error with the code "E_DOCUMENT_PICKER_CANCELED", however it should be throwing with the code "OPERATION_CANCELED" to match Android and match the expected value in the JS error codes constant.

JS error codes:

const OPERATION_CANCELED = 'OPERATION_CANCELED'
const IN_PROGRESS = 'ASYNC_OP_IN_PROGRESS'
const UNABLE_TO_OPEN_FILE_TYPE = 'UNABLE_TO_OPEN_FILE_TYPE'
/**
* Error codes that can be returned by the module, and are available on the `code` property of the error.
*
* @example
* ```ts
* const handleError = (err: unknown) => {
* if (isErrorWithCode(err)) {
* switch (err.code) {
* case errorCodes.IN_PROGRESS:
* ...
* break
* case errorCodes.UNABLE_TO_OPEN_FILE_TYPE:
* ...
* break
* case errorCodes.OPERATION_CANCELED:
* // ignore
* break
* default:
* console.error(err)
* }
* } else {
* console.error(err)
* }
* }
* ```
* */
export const errorCodes = Object.freeze({
OPERATION_CANCELED,
IN_PROGRESS,
UNABLE_TO_OPEN_FILE_TYPE,
})

Android error codes:

public static final String ASYNC_OP_IN_PROGRESS = "ASYNC_OP_IN_PROGRESS";
public static final String E_DOCUMENT_PICKER_CANCELED = "OPERATION_CANCELED";

@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2025

🦋 Changeset detected

Latest commit: 81b7a4c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@react-native-documents/picker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vonovak vonovak changed the title Fix iOS picker cancelled error code to match JS expected value fix(ios): picker cancelled error code to match JS expected value Jan 23, 2025
@vonovak vonovak merged commit 786223c into react-native-documents:main Jan 23, 2025
3 of 4 checks passed
@vonovak
Copy link
Member

vonovak commented Jan 23, 2025

Thanks for the PR! :)

@daveallie daveallie deleted the fix/ios-cancel-error-code-incorrect branch January 23, 2025 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants