-
Notifications
You must be signed in to change notification settings - Fork 9
Conversation
🦋 Changeset detectedLatest commit: 85e541a The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/http-client/src/client.ts
Outdated
try { | ||
pfiServiceEndpoint = await TbdexHttpClient.getPfiServiceEndpoint(pfiDid) | ||
} catch(e) { | ||
throw new RequestError({ message: e['message'], recipientDid: pfiDid, cause: e }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than catching and throwing the exception here, would it be more wise to throw the exception from within the TbdexHttpClient.getPfiServiceEndpoint
function? This is the beauty of using exceptions for error cases, rather than the return type, in that we can bubble-up the exceptions throughout n-number of callstack layers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch yep!
Nice! Embrace debate. I think it would be wise to be more fine-grained in our custom exceptions, with names that match the semantic failure. We're exchanging a design pattern where the return type has try {
await TbdexHttpClient.getOfferings({ pfiDid: 'hehetroll' })
} catch (e) {
if (e.message.include('invalidDid')) { // this line
console.log('This was an issue with the given DID')
} else if (e.message.include('has no PFI service entry')) { // and this line
console.log('This was a PFI discovery exception')
}
} But, if we fine-grained try {
await TbdexHttpClient.getOfferings({ pfiDid: 'hehetroll' })
} catch (e) {
if (e instanceof InvalidPfiDid) {
console.log('This was an issue with the given DID')
} else if (e instanceof EmptyPfiServiceEndpoint) {
console.log('This was a PFI discovery exception')
}
} With this approach, the general heuristic would be one-custom-exception-per-test-case |
bdfeb27
to
60e6ecb
Compare
@kirahsapong we thinking about refactoring the rest of |
@KendallWeihe could we address what you're bringing up by introducing a |
Could, and think it would be fine, but my intuition is against it. If we did, then we would want to define a type as a set of string literals, in the same way we do I think it's good for the DX, in that it would further add a layer of semantic reasoning to the developer of whether or not the given kind of exception was caused during the requesting or during the responding. But also, it's restrictive in that same sense in that certain kinds of exceptions may span both requesting and responding, in which case the additional hierarchy of categorization is useless overhead and only serves to confuse. I guess basically my point is, it's abstraction which doesn't offer net positive return. I think it better to have a flattened set of exceptions, where the name of the exception is the valuable nugget of experience. But, also, it's splitting hairs, so just do it one way or the other and it's fine 😆 |
@mistermoe good point might be nice to do 1 per PR to keep the review a bit tighter |
@KendallWeihe agree with your reasoning! |
7851abe
to
056b044
Compare
Added more info to the PR summary ✨ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
packages/http-client/src/client.ts
Outdated
@@ -27,7 +28,7 @@ export class TbdexHttpClient { | |||
* @throws if recipient DID resolution fails | |||
* @throws if recipient DID does not have a PFI service entry | |||
*/ | |||
static async sendMessage<T extends MessageKind>(opts: SendMessageOptions<T>): Promise<HttpResponse | ErrorResponse> { | |||
static async sendMessage<T extends MessageKind>(opts: SendMessageOptions<T>): Promise<HttpResponse> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts on just returning Promise<void>
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch thanks!
suppose we can remove DataResponse
from our types, with a lil bit of tech debt to refactor our http-server tests to remove our HttpResponse
and ErrorResponse
in a follow up, yeah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup good idea!
TBDocs Report ✅ No errors or warnings @tbdex/protocol
@tbdex/http-client
@tbdex/http-server
TBDocs Report Updated at 2023-12-20T19:01:22Z |
sendMessage getOfferings getExchange getExchanges getPfiServiceEndpoint
ad7978a
to
8153e4a
Compare
@kirahsapong as much as i want to use Did you have an approach in mind for conditionally switching between Otherwise, i think we can follow this example from web5-js to mock fetch! |
yeah have the same concern! my initial instinct is the overhead to switch betwixt will outweigh any benefit when all we're using msw for is stubbing fetch. i'm good to switcheroo! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice nice, can cut a new release 🚀
headers : response.headers, | ||
errors : responseBody.errors | ||
} | ||
if (!response.ok) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if this function returns nothing, that means the response was ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yee
oh yeah! last thing to note would be that we probably should add a |
Summary
This PR addresses #111
It adds custom error types including
RequestError
,ResponseError
,ValidationError
, custom validation error types includingInvalidDidError
andInvalidServiceEndpointError
.The
http-client
is refactored to throw a custom error type in case of a failure, and return data only in case of success.This PR only introduces more narrow custom error types for
ValidationError
s. We can track adding more narrow custom error types for request and response errors here.