Expose HttpError to plugins
This will let them throw and show nice errors more easily.
This commit is contained in:
@ -2,6 +2,7 @@ import { logger } from "@coder/logger"
|
||||
import * as express from "express"
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import { HttpCode } from "../src/common/http"
|
||||
import { PluginAPI } from "../src/node/plugin"
|
||||
import * as apps from "../src/node/routes/apps"
|
||||
import * as httpserver from "./httpserver"
|
||||
@ -81,4 +82,9 @@ describe("plugin", () => {
|
||||
ws.terminate()
|
||||
expect(message).toBe("hello")
|
||||
})
|
||||
|
||||
it("/test-plugin/error", async () => {
|
||||
const resp = await s.fetch("/test-plugin/error")
|
||||
expect(resp.status).toBe(HttpCode.LargePayload)
|
||||
})
|
||||
})
|
||||
|
@ -19,6 +19,9 @@ export const plugin: cs.Plugin = {
|
||||
r.get("/goland/icon.svg", (_, res) => {
|
||||
res.sendFile(fspath.resolve(__dirname, "../public/icon.svg"))
|
||||
})
|
||||
r.get("/error", () => {
|
||||
throw new cs.HttpError("error", cs.HttpCode.LargePayload)
|
||||
})
|
||||
return r
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user