FIX: Use standard error handling for requests, special-case moderators (#84)

By removing the catch and letting the error propagate to the top-level error handler, we can receive more detailed error reports including exactly which request failed.

The assumption that any request failure is a permissions error is replaced by an explicit client-side check before making any requests.
This commit is contained in:
Kane York 2020-12-07 15:13:14 -08:00 committed by GitHub
parent f70c95271a
commit 4506cf6a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,18 +1,23 @@
import { ajax } from "discourse/lib/ajax";
import User from "discourse/models/user";
import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({
controllerName: "admin-plugins-explorer",
model() {
if (!User.currentProp("admin")) {
// display "Only available to admins" message
return { model: null, schema: null, disallow: true, groups: null };
}
const groupPromise = ajax("/admin/plugins/explorer/groups.json");
const schemaPromise = ajax("/admin/plugins/explorer/schema.json", {
cache: true,
});
const queryPromise = this.store.findAll("query");
return groupPromise
.then((groups) => {
return groupPromise.then((groups) => {
let groupNames = {};
groups.forEach((g) => {
groupNames[g.id] = g.name;
@ -29,11 +34,6 @@ export default DiscourseRoute.extend({
return { model, schema, groups };
});
});
})
.catch(() => {
schemaPromise.catch(() => {});
queryPromise.catch(() => {});
return { model: null, schema: null, disallow: true, groups: null };
});
},