From 879cf1eb7cf04fe3bfe4cd5c93c5d9224cfbd8bd Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Sat, 11 Nov 2023 20:45:53 -0800 Subject: [PATCH 1/4] Restructure error messages as ErrorDetail --- packages/http-server/src/request-handlers/submit-rfq.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/http-server/src/request-handlers/submit-rfq.ts b/packages/http-server/src/request-handlers/submit-rfq.ts index 8fdecce3..eff356d2 100644 --- a/packages/http-server/src/request-handlers/submit-rfq.ts +++ b/packages/http-server/src/request-handlers/submit-rfq.ts @@ -18,7 +18,7 @@ export function submitRfq(options: SubmitRfqOpts): RequestHandler { try { message = await Message.parse(req.body) } catch(e) { - const errorResponse: ErrorDetail = { detail: e.message } + const errorResponse: ErrorDetail = { detail: `Parsing of TBDex message failed: ${e.message}` } return res.status(400).json({ errors: [errorResponse] }) } @@ -31,12 +31,14 @@ export function submitRfq(options: SubmitRfqOpts): RequestHandler { const rfqExists = !! await exchangesApi.getRfq({ exchangeId: message.id }) if (rfqExists) { - return res.status(409).json({ errors: [`rfq ${message.id} already exists`] }) + const errorResponse: ErrorDetail = { detail: `rfq ${message.id} already exists`} + return res.status(409).json({ errors: [errorResponse] }) } const offering = await offeringsApi.getOffering({ id: message.data.offeringId }) if (!offering) { - return res.status(400).json({ errors: [`offering ${message.data.offeringId} does not exist`] }) + const errorResponse: ErrorDetail = { detail: `offering ${message.data.offeringId} does not exist` } + return res.status(400).json({ errors: [errorResponse] }) } try { From 276184b5c9786811dc4159fd7ce659f440bdf149 Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Sat, 11 Nov 2023 21:02:06 -0800 Subject: [PATCH 2/4] Type response body of messages --- packages/http-server/src/types.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/http-server/src/types.ts b/packages/http-server/src/types.ts index 5b916d97..75ab35c2 100644 --- a/packages/http-server/src/types.ts +++ b/packages/http-server/src/types.ts @@ -1,5 +1,6 @@ import type { Request, Response } from 'express' import type { Close, MessageKindClass, MessageKindClasses, Offering, Order, OrderStatus, Quote, Rfq } from '@tbdex/protocol' +import type { ErrorDetail } from '@tbdex/http-client' /** * Union type for get requests @@ -89,7 +90,7 @@ export type RequestContext = { * Type alias for the request handler * @beta */ -export type RequestHandler = (request: Request, response: Response) => any +export type RequestHandler = (request: Request, response: Response<{ errors?: ErrorDetail[], data?: any }>) => any /** * PFI Offerings API From c4572dad005c8f26409a4b3359abfd8b5e33e216 Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Tue, 14 Nov 2023 10:37:15 +0000 Subject: [PATCH 3/4] Changeset --- .changeset/tiny-carrots-sort.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tiny-carrots-sort.md diff --git a/.changeset/tiny-carrots-sort.md b/.changeset/tiny-carrots-sort.md new file mode 100644 index 00000000..c48161c1 --- /dev/null +++ b/.changeset/tiny-carrots-sort.md @@ -0,0 +1,5 @@ +--- +"@tbdex/http-server": patch +--- + +Restructure error messages as ErrorDetail type From c635f819b5fc9ba12150fd2bcca13ba49b717aaf Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Tue, 14 Nov 2023 10:52:43 +0000 Subject: [PATCH 4/4] Typo --- packages/http-server/src/request-handlers/submit-rfq.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-server/src/request-handlers/submit-rfq.ts b/packages/http-server/src/request-handlers/submit-rfq.ts index eff356d2..2f75ab53 100644 --- a/packages/http-server/src/request-handlers/submit-rfq.ts +++ b/packages/http-server/src/request-handlers/submit-rfq.ts @@ -61,4 +61,4 @@ export function submitRfq(options: SubmitRfqOpts): RequestHandler { return res.sendStatus(202) } -} \ No newline at end of file +}