File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 11import fp from "fastify-plugin" ;
22import sensible from "@fastify/sensible" ;
3+ import { Type } from "@sinclair/typebox" ;
4+
5+ export const HttpError = Type . Ref ( "HttpError" ) ;
36
47/**
58 * This plugin adds some utilities to handle http errors.
69 *
710 * @see https://github.com/fastify/fastify-sensible
811 */
912export default fp ( async ( fastify ) => {
10- fastify . register ( sensible ) ;
13+ fastify . register ( sensible , {
14+ sharedSchemaId : "HttpError" ,
15+ } ) ;
1116} ) ;
Original file line number Diff line number Diff line change 11import { FastifyPluginAsync } from "fastify" ;
22import { FastifyTypebox } from "../../app.js" ;
33import { Type } from "@sinclair/typebox" ;
4+ import { HttpError } from "../../plugins/sensible.js" ;
45
56const example : FastifyPluginAsync = async (
67 fastify : FastifyTypebox ,
@@ -21,6 +22,21 @@ const example: FastifyPluginAsync = async (
2122 return "this is an example" ;
2223 } ,
2324 ) ;
25+ fastify . get (
26+ "/error" ,
27+ {
28+ schema : {
29+ summary : "Get Example with Some Errors" ,
30+ tags : [ "Example" ] ,
31+ response : {
32+ 200 : HttpError ,
33+ } ,
34+ } ,
35+ } ,
36+ async function ( request , reply ) {
37+ return reply . badRequest ( "this is an error example" ) ;
38+ } ,
39+ ) ;
2440} ;
2541
2642export default example ;
You can’t perform that action at this time.
0 commit comments