Skip to content

Commit

Permalink
chore(core): address pr feedback
Browse files Browse the repository at this point in the history
- correct error names
- use tracing in lnurl-pay service
  • Loading branch information
UncleSamtoshi committed Dec 18, 2023
1 parent 44260a8 commit 2325f80
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions core/api/src/app/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as CallbackErrors from "@/domain/callback/errors"
import * as CommErrors from "@/domain/comm/errors"
import * as OnChainErrors from "@/domain/bitcoin/onchain/errors"
import * as LightningErrors from "@/domain/bitcoin/lightning/errors"
import * as LnurlErrors from "@/domain/bitcoin/lnurl/errors"
import * as LnurlServiceErrors from "@/domain/bitcoin/lnurl/errors"
import * as PriceServiceErrors from "@/domain/price/errors"
import * as LockServiceErrors from "@/domain/lock/errors"
import * as RateLimitServiceErrors from "@/domain/rate-limit/errors"
Expand Down Expand Up @@ -36,7 +36,7 @@ export const ApplicationErrors = {
...CommErrors,
...OnChainErrors,
...LightningErrors,
...LnurlErrors,
...LnurlServiceErrors,
...PriceServiceErrors,
...LockServiceErrors,
...RateLimitServiceErrors,
Expand Down
6 changes: 3 additions & 3 deletions core/api/src/domain/bitcoin/lnurl/errors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DomainError, ErrorLevel } from "@/domain/shared"

export class LnurlError extends DomainError {}
export class ErrorFetchingLnurlInvoice extends LnurlError {}
export class UnknownLnurlError extends LnurlError {
export class LnurlServiceError extends DomainError {}
export class ErrorFetchingLnurlInvoice extends LnurlServiceError {}
export class UnknownLnurlServiceError extends LnurlServiceError {
level = ErrorLevel.Critical
}
4 changes: 2 additions & 2 deletions core/api/src/domain/bitcoin/lnurl/index.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type LnurlError = import("@/domain/bitcoin/lnurl/errors").LnurlError
type LnurlServiceError = import("@/domain/bitcoin/lnurl/errors").LnurlServiceError
interface ILnurlPayService {
fetchInvoiceFromLnAddressOrLnurl(args: {
amount: BtcPaymentAmount
lnAddressOrLnurl: string
}): Promise<string | LnurlError>
}): Promise<string | LnurlServiceError>
}
4 changes: 2 additions & 2 deletions core/api/src/graphql/error-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ export const mapError = (error: ApplicationError): CustomGraphQLError => {
case "ExpectedAddressInfoMissingInEventError":
case "MissingCreatedAtKratosError":
case "MissingExpiredAtKratosError":
case "LnurlError":
case "LnurlServiceError":
case "InvalidIdentitySessionKratosError":
case "MissingTotpKratosError":
case "IncompatibleSchemaUpgradeError":
Expand Down Expand Up @@ -730,7 +730,7 @@ export const mapError = (error: ApplicationError): CustomGraphQLError => {
case "UnknownOnChainServiceError":
case "UnknownNotificationsServiceError":
case "UnknownIpFetcherServiceError":
case "UnknownLnurlError":
case "UnknownLnurlServiceError":
case "UnknownCacheServiceError":
case "UnknownPhoneProviderServiceError":
case "UnknownDealerPriceServiceError":
Expand Down
18 changes: 11 additions & 7 deletions core/api/src/services/lnurl-pay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { utils, requestInvoice } from "lnurl-pay"
import { toSats } from "@/domain/bitcoin"
import {
ErrorFetchingLnurlInvoice,
LnurlError,
UnknownLnurlError,
LnurlServiceError,
UnknownLnurlServiceError,
} from "@/domain/bitcoin/lnurl/errors"
import { wrapAsyncFunctionsToRunInSpan } from "../tracing"

export const LnurlPayService = (): ILnurlPayService => {
const fetchInvoiceFromLnAddressOrLnurl = async ({
Expand All @@ -14,7 +15,7 @@ export const LnurlPayService = (): ILnurlPayService => {
}: {
amount: BtcPaymentAmount
lnAddressOrLnurl: string
}): Promise<string | LnurlError> => {
}): Promise<string | LnurlServiceError> => {
try {
const invoice = await requestInvoice({
lnUrlOrAddress: lnAddressOrLnurl,
Expand All @@ -32,11 +33,14 @@ export const LnurlPayService = (): ILnurlPayService => {
if (err instanceof Error) {
return new ErrorFetchingLnurlInvoice(err.message)
}
return new UnknownLnurlError(err)
return new UnknownLnurlServiceError(err)
}
}

return {
fetchInvoiceFromLnAddressOrLnurl,
}
return wrapAsyncFunctionsToRunInSpan({
namespace: "services.lnurl-pay",
fns: {
fetchInvoiceFromLnAddressOrLnurl,
},
})
}

0 comments on commit 2325f80

Please sign in to comment.