Skip to content

Commit ac532ed

Browse files
authored
log errors when using the url option (#57)
1 parent 45a1c1f commit ac532ed

File tree

3 files changed

+53
-26
lines changed

3 files changed

+53
-26
lines changed

dist/index.js

+26-11
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,31 @@ async function fromURL(url, email = "", password = "") {
2525
const formData = new FormData();
2626
formData.append("identity", email);
2727
formData.append("password", password);
28-
const { token } = await fetch(`${url}/api/admins/auth-with-password`, {
29-
body: formData,
30-
method: "post"
31-
}).then((res) => res.json());
32-
const result = await fetch(`${url}/api/collections?perPage=200`, {
33-
headers: {
34-
Authorization: token
35-
}
36-
}).then((res) => res.json());
37-
return result.items;
28+
let collections = [];
29+
try {
30+
const { token } = await fetch(`${url}/api/admins/auth-with-password`, {
31+
body: formData,
32+
method: "post"
33+
}).then((res) => {
34+
if (!res.ok)
35+
throw res;
36+
return res.json();
37+
});
38+
const result = await fetch(`${url}/api/collections?perPage=200`, {
39+
headers: {
40+
Authorization: token
41+
}
42+
}).then((res) => {
43+
if (!res.ok)
44+
throw res;
45+
return res.json();
46+
});
47+
collections = result.items;
48+
} catch (error) {
49+
console.error(error);
50+
process.exit(1);
51+
}
52+
return collections;
3853
}
3954

4055
// src/constants.ts
@@ -269,7 +284,7 @@ async function main(options2) {
269284
import { program } from "commander";
270285

271286
// package.json
272-
var version = "1.1.7";
287+
var version = "1.1.8";
273288

274289
// src/index.ts
275290
program.name("Pocketbase Typegen").version(version).description(

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pocketbase-typegen",
3-
"version": "1.1.7",
3+
"version": "1.1.8",
44
"description": "Generate pocketbase record types from your database",
55
"main": "dist/index.js",
66
"bin": {

src/schema.ts

+26-14
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,32 @@ export async function fromURL(
3232
const formData = new FormData()
3333
formData.append("identity", email)
3434
formData.append("password", password)
35+
let collections: Array<CollectionRecord> = []
36+
try {
37+
// Login
38+
const { token } = await fetch(`${url}/api/admins/auth-with-password`, {
39+
// @ts-ignore
40+
body: formData,
41+
method: "post",
42+
}).then((res) => {
43+
if (!res.ok) throw res
44+
return res.json()
45+
})
3546

36-
// Login
37-
const { token } = await fetch(`${url}/api/admins/auth-with-password`, {
38-
// @ts-ignore
39-
body: formData,
40-
method: "post",
41-
}).then((res) => res.json())
47+
// Get the collections
48+
const result = await fetch(`${url}/api/collections?perPage=200`, {
49+
headers: {
50+
Authorization: token,
51+
},
52+
}).then((res) => {
53+
if (!res.ok) throw res
54+
return res.json()
55+
})
56+
collections = result.items
57+
} catch (error) {
58+
console.error(error)
59+
process.exit(1)
60+
}
4261

43-
// Get the collection
44-
const result = await fetch(`${url}/api/collections?perPage=200`, {
45-
headers: {
46-
Authorization: token,
47-
},
48-
}).then((res) => res.json())
49-
50-
return result.items as Array<CollectionRecord>
62+
return collections
5163
}

0 commit comments

Comments
 (0)