mw.Upload: Refactor error handling for the umpteenth time
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 8 Oct 2015 20:10:46 +0000 (22:10 +0200)
committerJames D. Forrester <jforrester@wikimedia.org>
Mon, 12 Oct 2015 19:26:18 +0000 (15:26 -0400)
commitb21ef76c8e95bc6958a80638946048ed8963a10b
tree295083734e9133b2378ab766a28339b2bc9bc915
parent85aaeace197dbce2999384237bdbb7d6a7d15d62
mw.Upload: Refactor error handling for the umpteenth time

When I started, I just wanted mw.Upload.BookletLayout to be able to
display more information about errors than just the default message
(like it can do for warnings). And down the rabbit hole I went...

mediawiki/api/upload.js:
* Simply throw errors when our methods are called with bad parameters,
  rather than return a rejected promise.
* Always call .notify( 1 ) when upload is complete, regardless of
  whether it succeeded or failed.
* Reject promises with error code and error details, for consistency
  with api.js. Previous behavior meant that we did not let callers
  know the details in some cases. It was also problematic when we
  passed-through promises rejected in api.js (which had different
  parameters given).
  * Made some effort to return sane codes when something intricate
    fails in iframe upload, but no guarantee that this works well. The
    codes are inspired by what api.js returns in similar circumstances.
  * When rejecting because of warnings, use the first warning's key as
    error code.
  * Always ignore the warnings when uploading to stash and 'filekey'
    is present in response, never ignore when uploading directly.
* When the upload succeeds, never check for 'result.upload.error'
  (which just isn't a thing) nor for 'result.error' (which api.js
  detects and rejects the promise before we get to it). We only need
  to check for 'result.upload.warnings'.

mediawiki.Upload.js:
* Update for the above changes in mediawiki/api/upload.js.
* More reliably distinguish warnings from errors in all cases, not
  only when finishing a stash upload.
* Store machine-readable error codes, not mw.Message objects. This
  lets callers do something sensible when we encounter an unknown
  error (especially one that has no corresponding message).
* Store full result as state details for warnings, as well as errors.

mediawiki.Upload.BookletLayout.js:
* Update for the above changes in mediawiki.Upload.js.
* Give errors/warnings generated during upload to stash the same
  loving treatment as errors/warnings during publishing.
  * Extract the code to a new method getErrorMessageForStateDetails().
* Handle 'stashfailed' warning (which is really an error).
* Handle unknown errors, now that mw.Upload lets us do something
  sensible with them. (See, this is the thing I set out to do.)

Bug: T114940
Change-Id: I4c0f619a4e483cca296c2fa2907ed1f81a99fdd6
resources/Resources.php
resources/src/mediawiki/api/upload.js
resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
resources/src/mediawiki/mediawiki.Upload.js
tests/qunit/suites/resources/mediawiki.api/mediawiki.api.upload.test.js