feat: add bun-fullstack agent and update skills
This commit is contained in:
38
.opencode/skills/tech-stack/elysiajs/examples/error.ts
Normal file
38
.opencode/skills/tech-stack/elysiajs/examples/error.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Elysia, t } from 'elysia'
|
||||
|
||||
class CustomError extends Error {
|
||||
constructor(public name: string) {
|
||||
super(name)
|
||||
}
|
||||
}
|
||||
|
||||
new Elysia()
|
||||
.error({
|
||||
CUSTOM_ERROR: CustomError
|
||||
})
|
||||
// global handler
|
||||
.onError(({ code, error, status }) => {
|
||||
switch (code) {
|
||||
case "CUSTOM_ERROR":
|
||||
return status(401, { message: error.message })
|
||||
|
||||
case "NOT_FOUND":
|
||||
return "Not found :("
|
||||
}
|
||||
})
|
||||
.post('/', ({ body }) => body, {
|
||||
body: t.Object({
|
||||
username: t.String(),
|
||||
password: t.String(),
|
||||
nested: t.Optional(
|
||||
t.Object({
|
||||
hi: t.String()
|
||||
})
|
||||
)
|
||||
}),
|
||||
// local handler
|
||||
error({ error }) {
|
||||
console.log(error)
|
||||
}
|
||||
})
|
||||
.listen(3000)
|
||||
Reference in New Issue
Block a user