Steps to replicate the issue (include links if applicable):
On browser debug console:
const rest = new mw.Rest(); await rest.post("/v1/transform/wikitext/to/html", { wikitext: "{{citation needed}}" }).catch(console.error)
What happens?:
An http JQuery error is thrown, with the following exception:
SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
at parse (<anonymous>)
at ajaxConvert (jquery.js:9099:19)
at done (jquery.js:9577:15)
at XMLHttpRequest.<anonymous> (jquery.js:9888:9)JQuery attempts to convert the response (text/html) to JSON.
What should have happened instead?:
No error should have been thrown, a string containing the response text should have been returned.
Software version: 1.42.0-wmf.7 (6765518)
Other information:
This is probably more of a JavaScript issue, since mediawiki.api/rest.js:118 currently forces dataType: 'json'. Setting dataType to nothing allows JQuery to intelligently guess the data type and automatically return the appropriate data type (e.g. returning JSON if the Content-Type matches /\bjson\b/, exact mechanism for this found here+here). Omitting the dataType will probably be fine, as long as the REST API always sends the correct Content-Type response header, but this will affect everything that consumes from the REST API using mw.Rest and I don't have any definitive evidence that Content-Types are always accurate so I'll leave the choice of what to do here up to someone who can make a more-informed decision.