Ops API typing
This commit is contained in:
parent
b1dc997390
commit
4bf23b0163
|
@ -1,16 +1,7 @@
|
||||||
import { Ctx } from "@budibase/types"
|
import { Ctx, LogOpsRequest, ErrorOpsRequest } from "@budibase/types"
|
||||||
import { logging } from "@budibase/backend-core"
|
import { logging } from "@budibase/backend-core"
|
||||||
|
|
||||||
interface LogRequest {
|
export async function log(ctx: Ctx<LogOpsRequest, void>) {
|
||||||
message: string
|
|
||||||
data?: any
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ErrorRequest {
|
|
||||||
message: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function log(ctx: Ctx<LogRequest>) {
|
|
||||||
const body = ctx.request.body
|
const body = ctx.request.body
|
||||||
console.trace(body.message, body.data)
|
console.trace(body.message, body.data)
|
||||||
console.debug(body.message, body.data)
|
console.debug(body.message, body.data)
|
||||||
|
@ -20,13 +11,13 @@ export async function log(ctx: Ctx<LogRequest>) {
|
||||||
ctx.status = 204
|
ctx.status = 204
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function alert(ctx: Ctx<ErrorRequest>) {
|
export async function alert(ctx: Ctx<ErrorOpsRequest, void>) {
|
||||||
const body = ctx.request.body
|
const body = ctx.request.body
|
||||||
logging.logAlert(body.message, new Error(body.message))
|
logging.logAlert(body.message, new Error(body.message))
|
||||||
ctx.status = 204
|
ctx.status = 204
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function error(ctx: Ctx<ErrorRequest>) {
|
export async function error(ctx: Ctx<ErrorOpsRequest, void>) {
|
||||||
const body = ctx.request.body
|
const body = ctx.request.body
|
||||||
throw new Error(body.message)
|
throw new Error(body.message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
export * from "./environment"
|
export * from "./environment"
|
||||||
export * from "./status"
|
export * from "./status"
|
||||||
|
export * from "./ops"
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
export interface LogOpsRequest {
|
||||||
|
message: string
|
||||||
|
data?: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ErrorOpsRequest {
|
||||||
|
message: string
|
||||||
|
}
|
Loading…
Reference in New Issue