frontend: always raise advice about missing glslangValidator
[nit.git] / src / web / api_model.nit
index 63fd636..4c9fb8e 100644 (file)
@@ -18,6 +18,21 @@ import web_base
 import highlight
 import uml
 
+redef class APIRouter
+       redef init do
+               super
+               use("/list", new APIList(config))
+               use("/search", new APISearch(config))
+               use("/random", new APIRandom(config))
+               use("/entity/:id", new APIEntity(config))
+               use("/code/:id", new APIEntityCode(config))
+               use("/uml/:id", new APIEntityUML(config))
+               use("/linearization/:id", new APIEntityLinearization(config))
+               use("/defs/:id", new APIEntityDefs(config))
+               use("/inheritance/:id", new APIEntityInheritance(config))
+       end
+end
+
 # List all mentities.
 #
 # MEntities can be filtered on their kind using the `k` parameter.
@@ -128,10 +143,7 @@ class APIEntityInheritance
 
        redef fun get(req, res) do
                var mentity = mentity_from_uri(req, res)
-               if mentity == null then
-                       res.error 404
-                       return
-               end
+               if mentity == null then return
                res.json mentity.hierarchy_poset(view)[mentity]
        end
 end
@@ -144,13 +156,10 @@ class APIEntityLinearization
 
        redef fun get(req, res) do
                var mentity = mentity_from_uri(req, res)
-               if mentity == null then
-                       res.error 404
-                       return
-               end
+               if mentity == null then return
                var lin = mentity.collect_linearization(config.mainmodule)
                if lin == null then
-                       res.error 404
+                       res.api_error(404, "No linearization for mentity `{mentity.full_name}`")
                        return
                end
                res.json new JsonArray.from(lin)
@@ -165,6 +174,7 @@ class APIEntityDefs
 
        redef fun get(req, res) do
                var mentity = mentity_from_uri(req, res)
+               if mentity == null then return
                var arr = new JsonArray
                if mentity isa MModule then
                        for mclassdef in mentity.mclassdefs do arr.add mclassdef
@@ -175,7 +185,7 @@ class APIEntityDefs
                else if mentity isa MProperty then
                        for mpropdef in mentity.mpropdefs do arr.add mpropdef
                else
-                       res.error 404
+                       res.api_error(404, "No definition list for mentity `{mentity.full_name}`")
                        return
                end
                res.json arr
@@ -203,6 +213,7 @@ class APIEntityUML
 
        redef fun get(req, res) do
                var mentity = mentity_from_uri(req, res)
+               if mentity == null then return
                var dot
                if mentity isa MClassDef then mentity = mentity.mclass
                if mentity isa MClass then
@@ -212,7 +223,7 @@ class APIEntityUML
                        var uml = new UMLModel(view, mentity)
                        dot = uml.generate_package_uml.write_to_string
                else
-                       res.error 404
+                       res.api_error(404, "No UML for mentity `{mentity.full_name}`")
                        return
                end
                res.send render_dot(dot)
@@ -230,7 +241,7 @@ class APIEntityCode
                if mentity == null then return
                var source = render_source(mentity)
                if source == null then
-                       res.error 404
+                       res.api_error(404, "No code for mentity `{mentity.full_name}`")
                        return
                end
                res.send source