Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

morebits: pass api object to failure handlers wherever possible #679

Closed

Conversation

siddharthvp
Copy link
Member

Pass the morebits.wiki.api object (rather than the morebits.wiki.page object) to the failure callbacks wherever possible, except where the error is being handled before any API calls are made (such as when trying to protect without being admin or without setting the protection settings). The apiobj is more useful since it has the errorCode, using which the client script may choose to show customised error messages. The pageobj is anyway still accessible as it is set as the parent attribute of apiobj in all usages.

Regarding the success callbacks, save() is currently giving the pageobj (useful to allow further processing with the page) while the other functions are giving the apiobj. No changes made here.

See individual commit messages for more details.

This does not break any existing code.

Presently, the morebits.wiki.page object is passed to the failure handler.
But this object is of no use as it contains no information about the error.
The morebits.wiki.api object is more useful as it carries the errorCode and
errorText properties, and can thus be used to determine the error and produce
a customised error message.

Also, the page object still remains accessible as it is the parent attribute
of the api object. (While the api object is not accessible from the page object.)

The success callback continues to take the page object as parameter. This is
probably desired for the success callback to allow additional processing with
the page after save.

This change does not break anything in Twinkle.
…acks

Give the apiobj as the parameter to the failure handler on all types of errors (except, of course,
when the error is handled before any API calls take place), rather
than doing the mix of giving the pageobj on some errors and apiobj on some errors.

L2856 - `ctx.onDeleteFailure.call(this, this, ctx.deleteProcessApi);` was most probably a typo, as
it passes two arguments to the fail callback, which is not done anywhere else.

Remove `if (ctx.onDeleteFailure)` checks since these will always evaluate to true, as
`ctx.onDelelteFailure` fallbacks to an empty function (L2301) if not given by user.
Use moveApi object as parameter to the `ctx.onMoveFailure` if issue is detected after moveApi stage.
The moveProcessApi object is already being passed to `ctx.onMoveSuccess` and `ctx.onMoveFailure`
when the move succeeds or when moveProcessApi is failing.
Same changes as done with move function.

When an issue is detected after protectApi, pass protectApi object to failure callback.

When protection succeeds or protectProcessApi fails, the protectProcessApi object is already being
passed to the success/failure callbacks.
…backs

Similar to what is done in morebits.wiki.page.deletePage().
@Amorymeltzer Amorymeltzer added the Module: morebits The morebits.js library label Jun 19, 2019
None of fnProcessDelete, fnProcessUndelete, or fnDoneOne take an argument.
@siddharthvp siddharthvp changed the title morebits: improve consistency in parameters passed to callbacks morebits: pass api object to failure handlers wherever possible Aug 31, 2019
@Amorymeltzer Amorymeltzer self-assigned this Nov 17, 2019
@siddharthvp
Copy link
Member Author

Closing in favour of a superior solution described in #783.

@Amorymeltzer Amorymeltzer removed their assignment Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: morebits The morebits.js library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants