This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Refactor http client #113
Merged
Merged
Refactor http client #113
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d65b472
start refactor
mistermoe 74e2bb7
add deps
mistermoe b58e0f6
Add msw and more tests
kirahsapong a73e8e0
Add todo comment
kirahsapong bbd420b
fix deps
kirahsapong c7470a7
Add validation errors
kirahsapong 1642ac0
Add sinon pkg
kirahsapong d9b47f8
Refactor client
kirahsapong e49885e
Add mocks and tests for sendMessage, getOfferings, and getPfiServiceE…
kirahsapong dc4e352
Add tests for getExchange and getExchanges
kirahsapong 9397438
small revert
kirahsapong 69f703e
small import fix
kirahsapong e5302f3
small revert
kirahsapong 42f729b
remove httpresponse return val from sendmessage
kirahsapong 70a617f
Rename InvalidServiceEndpointError to MissingServiceEndpointError
kirahsapong 8153e4a
Remove DataResponse type
kirahsapong d0858ca
Remove msw in favour of sinon stub
kirahsapong 0f56b70
Remove msw pkg
kirahsapong 02a9006
Add changeset
kirahsapong 85e541a
Update changeset
kirahsapong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tbdex/http-client": minor | ||
--- | ||
|
||
Introduces custom errors types and breaking changes: functions now throw instead of return on failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { RequestError } from './request-error.js' | ||
export { ResponseError } from './response-error.js' | ||
export { ValidationError, InvalidDidError, MissingServiceEndpointError } from './validation-error.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export type RequestErrorParams = { | ||
message: string | ||
recipientDid: string | ||
url?: string | ||
cause?: unknown | ||
} | ||
|
||
/** | ||
* Error thrown when making HTTP requests | ||
* @beta | ||
*/ | ||
export class RequestError extends Error { | ||
public readonly recipientDid: string | ||
public readonly url: string | ||
|
||
constructor(params: RequestErrorParams) { | ||
super(params.message, { cause: params.cause }) | ||
|
||
this.name = this.constructor.name | ||
this.recipientDid = params.recipientDid | ||
this.url = params.url | ||
|
||
Object.setPrototypeOf(this, RequestError.prototype) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { ErrorDetail } from '../types.js' | ||
|
||
export type ResponseErrorParams = { | ||
statusCode: number | ||
details: ErrorDetail[] | ||
recipientDid: string | ||
url: string | ||
} | ||
|
||
/** | ||
* Error thrown when getting HTTP responses | ||
* @beta | ||
*/ | ||
export class ResponseError extends Error { | ||
public readonly statusCode: number | ||
public readonly details: ErrorDetail[] | ||
public readonly recipientDid: string | ||
public readonly url: string | ||
|
||
constructor(params: ResponseErrorParams) { | ||
super() | ||
|
||
this.name = this.constructor.name | ||
this.statusCode = params.statusCode | ||
this.details = params.details | ||
this.recipientDid = params.recipientDid | ||
this.url = params.url | ||
|
||
Object.setPrototypeOf(this, ResponseError.prototype) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export type ValidationErrorParams = { | ||
message: string | ||
} | ||
|
||
/** | ||
* Error thrown when validating data | ||
* @beta | ||
*/ | ||
export class ValidationError extends Error { | ||
constructor(message: string) { | ||
super(message) | ||
|
||
this.name = this.constructor.name | ||
|
||
Object.setPrototypeOf(this, ValidationError.prototype) | ||
} | ||
} | ||
|
||
/** | ||
* Error thrown when a DID is invalid | ||
* @beta | ||
*/ | ||
export class InvalidDidError extends ValidationError { | ||
constructor(message: string) { | ||
super(message) | ||
|
||
Object.setPrototypeOf(this, InvalidDidError.prototype) | ||
} | ||
} | ||
|
||
/** | ||
* Error thrown when a PFI's service endpoint can't be found | ||
* @beta | ||
*/ | ||
export class MissingServiceEndpointError extends ValidationError { | ||
constructor(message: string) { | ||
super(message) | ||
|
||
Object.setPrototypeOf(this, MissingServiceEndpointError.prototype) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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