xataio / client-ts

Xata.io SDK for TypeScript and JavaScript
https://xata.io/docs/sdk/typescript/overview
Apache License 2.0
123 stars 8 forks source link

Add methods that throw #559

Closed fabien0102 closed 2 years ago

fabien0102 commented 2 years ago

Describe the bug With the following code (simple expressjs app)

// Delete climber
  app.delete("/climbers/:id", async (req, res) => {
    const id = req.params.id;

    try {
      console.log("try");
      await xata.db.climbers.delete(id);
      console.log("success", id);

      res.status(204).send();
    } catch {
      res.status(400).json({
        message: "Can't delete this record",
      });
    }
  });

I was expecting a 400 status if I send "yolo" as id but instead I have a 204 and this in my console:

image

Expected behavior I was expecting to throw an exception since the id is not valid.

Software version

"@xata.io/client": "0.16.1"

SferaDev commented 2 years ago

We don't throw on any error, when there's a situation not possible we return null. We have discussed in the past adding actionOrThrow methods: https://xata-hq.slack.com/archives/C032EKCBUGM/p1657121418430689?thread_ts=1657121418.430689&cid=C032EKCBUGM

Will keep this issue to implement those.

fabien0102 commented 2 years ago

image

Sorry if my original issue was not clear enough, but from the method documentation, this method should throws if the record can't be found.