@kiyeonjeon21/ncli 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/datalab.js +3 -12
- package/dist/commands/search.js +2 -6
- package/dist/core/client.js +1 -1
- package/dist/core/error.d.ts +1 -0
- package/dist/core/error.js +19 -0
- package/package.json +1 -1
package/dist/commands/datalab.js
CHANGED
|
@@ -4,6 +4,7 @@ import { NaverClient } from "../core/client.js";
|
|
|
4
4
|
import { getOutputFormat, getFieldMask, printOutput, printJson } from "../core/output.js";
|
|
5
5
|
import { getSchema } from "../schemas/index.js";
|
|
6
6
|
import { readJsonArg } from "../core/stdin.js";
|
|
7
|
+
import { writeError } from "../core/error.js";
|
|
7
8
|
const DATALAB_BASE_URL = "https://openapi.naver.com/v1/datalab";
|
|
8
9
|
export const datalabCommand = new Command("datalab").description("Naver DataLab trend and shopping insight APIs. Rate limit: 1,000/day");
|
|
9
10
|
datalabCommand
|
|
@@ -43,12 +44,7 @@ Schema: ncli schema datalab.trend`)
|
|
|
43
44
|
printOutput(data, format, fields ?? undefined);
|
|
44
45
|
}
|
|
45
46
|
catch (err) {
|
|
46
|
-
|
|
47
|
-
error: {
|
|
48
|
-
code: "COMMAND_FAILED",
|
|
49
|
-
message: err instanceof Error ? err.message : String(err),
|
|
50
|
-
},
|
|
51
|
-
}) + "\n");
|
|
47
|
+
writeError(err);
|
|
52
48
|
process.exit(1);
|
|
53
49
|
}
|
|
54
50
|
});
|
|
@@ -89,12 +85,7 @@ Schema: ncli schema datalab.shopping`)
|
|
|
89
85
|
printOutput(data, format, fields ?? undefined);
|
|
90
86
|
}
|
|
91
87
|
catch (err) {
|
|
92
|
-
|
|
93
|
-
error: {
|
|
94
|
-
code: "COMMAND_FAILED",
|
|
95
|
-
message: err instanceof Error ? err.message : String(err),
|
|
96
|
-
},
|
|
97
|
-
}) + "\n");
|
|
88
|
+
writeError(err);
|
|
98
89
|
process.exit(1);
|
|
99
90
|
}
|
|
100
91
|
});
|
package/dist/commands/search.js
CHANGED
|
@@ -5,6 +5,7 @@ import { getOutputFormat, getFieldMask, printOutput, printJson } from "../core/o
|
|
|
5
5
|
import { validateAgentInput, sanitizeResponse } from "../core/validate.js";
|
|
6
6
|
import { getSchema } from "../schemas/index.js";
|
|
7
7
|
import { readJsonArg } from "../core/stdin.js";
|
|
8
|
+
import { writeError } from "../core/error.js";
|
|
8
9
|
const SEARCH_TYPES = [
|
|
9
10
|
"blog",
|
|
10
11
|
"news",
|
|
@@ -163,12 +164,7 @@ for (const type of SEARCH_TYPES) {
|
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
catch (err) {
|
|
166
|
-
|
|
167
|
-
error: {
|
|
168
|
-
code: "COMMAND_FAILED",
|
|
169
|
-
message: err instanceof Error ? err.message : String(err),
|
|
170
|
-
},
|
|
171
|
-
}) + "\n");
|
|
167
|
+
writeError(err);
|
|
172
168
|
process.exit(1);
|
|
173
169
|
}
|
|
174
170
|
});
|
package/dist/core/client.js
CHANGED
|
@@ -18,7 +18,7 @@ function parseNaverError(status, body) {
|
|
|
18
18
|
return {
|
|
19
19
|
error: {
|
|
20
20
|
code: `HTTP_${status}`,
|
|
21
|
-
message: hint ? `${errorMessage} (${hint})` : errorMessage
|
|
21
|
+
message: hint ? `${errorMessage} (${hint})` : errorMessage || `HTTP ${status} error`,
|
|
22
22
|
status,
|
|
23
23
|
naverCode: errorCode || undefined,
|
|
24
24
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeError(err: unknown): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function writeError(err) {
|
|
2
|
+
if (err instanceof Error) {
|
|
3
|
+
// If message is already a JSON error from client.ts, pass through
|
|
4
|
+
try {
|
|
5
|
+
const parsed = JSON.parse(err.message);
|
|
6
|
+
if (parsed.error) {
|
|
7
|
+
process.stderr.write(JSON.stringify(parsed) + "\n");
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// not JSON, wrap it
|
|
13
|
+
}
|
|
14
|
+
process.stderr.write(JSON.stringify({ error: { code: "COMMAND_FAILED", message: err.message } }) + "\n");
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
process.stderr.write(JSON.stringify({ error: { code: "COMMAND_FAILED", message: String(err) } }) + "\n");
|
|
18
|
+
}
|
|
19
|
+
}
|