Skip to content

Internal Server Error when requested conversion amount is too small #7

@sc4l3r

Description

@sc4l3r

When I request a conversion with an amount which, because of the conversion rate, would result in a converted amount of less than 1n, an Internal Server Error is returned.

In the server logs I see:

[<NO_REQUEST_ID>] DEBUG Calculating exchange rate for BTC -> USD:
[<NO_REQUEST_ID>] DEBUG Base rate: 125341.55998122648:
[<NO_REQUEST_ID>] DEBUG Converted:: 0n
[<NO_REQUEST_ID>] ERROR KeetaAnchorHTTP.Server: Error: Invalid converted amount
    at Object.getConversionRateAndFee (/workspace/demo-fx-anchor/apps/api/src/app.ts:44:11)

Expected Behavior

A Bad Request response is returned with a message that indicates what I did wrong, e.g. "Requested amount is too small".

Steps to reproduce

  1. Start the anchor (or use the one deployed at https://demo-fx-anchor.test.keeta.com).

  2. Request a conversion of 1n BTC (0.00000001) to USD:

    curl 'http://localhost:8080/api/getEstimate' \
      -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' \
      --data-raw '{"request":{"from":"keeta_ao47xyunmfh5jcdkm7mgrfaaddp7a2nt2xvwrph6cgurvbeixh77qkfsglgms","to":"keeta_ap7wtjtyfc4yvt26jstau4n76uqnv4znjnz5pcgpnjsty5vjbxkvmk55yl4f6","amount":"0x1","affinity":"from"}}'
  3. Observe the response {"ok":false,"error":"Internal Server Error"}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions