Skip to content

Commit

Permalink
fix: add try-catch to get error message
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvuongngo authored Nov 25, 2024
1 parent 8257ae3 commit 5d56ae2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions content/spin/v3/rdbms-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ const DB_URL = "mysql://root:@127.0.0.1/spin_dev"
*/

export async function handler(_req: Request, res: ResponseBuilder) {
let conn = Mysql.open(DB_URL);
conn.execute('delete from test where id=$1', [4]);
conn.execute('insert into test values (4,5)', []);
let ret = conn.query('select * from test', []);
// return a object that looks like
// { "columns": [{name: "id", dataType: "int32"}], "rows": [{ "id": 4, "val": 5 }] }
res.send(JSON.stringify(ret, null, 2));
try {
let conn = Mysql.open(DB_URL);
conn.execute('delete from test where id=$1', [4]);
conn.execute('insert into test values (4,5)', []);
let ret = conn.query('select * from test', []);
// return a object that looks like
// { "columns": [{name: "id", dataType: "int32"}], "rows": [{ "id": 4, "val": 5 }] }
res.send(JSON.stringify(ret, null, 2));
} catch (error) {
console.log(error.payload);
res.send({});
}
}
```

Expand Down

0 comments on commit 5d56ae2

Please sign in to comment.