@przeprogramowani/10x-cli 1.3.0 → 1.3.1
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/index.mjs +45 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2271,7 +2271,7 @@ var cac = (name = "") => new CAC(name);
|
|
|
2271
2271
|
// package.json
|
|
2272
2272
|
var package_default = {
|
|
2273
2273
|
name: "@przeprogramowani/10x-cli",
|
|
2274
|
-
version: "1.3.
|
|
2274
|
+
version: "1.3.1",
|
|
2275
2275
|
description: "Open-source CLI for 10xDevs course content",
|
|
2276
2276
|
repository: {
|
|
2277
2277
|
type: "git",
|
|
@@ -3034,6 +3034,37 @@ function resolveApiBase() {
|
|
|
3034
3034
|
throw new Error(`API_BASE_URL must be ${DEFAULT_API_BASE} or http://localhost[:port] (got ${JSON.stringify(override)})`);
|
|
3035
3035
|
}
|
|
3036
3036
|
var DEFAULT_TIMEOUT_MS = 30000;
|
|
3037
|
+
var UNKNOWN_API_ERROR_MESSAGE = "An unknown error occurred. Please contact 10xDevs mentors and share the command that caused this. Sorry for the issue!";
|
|
3038
|
+
var ERROR_CODE_MESSAGES = {
|
|
3039
|
+
course_not_found: "Course not found.",
|
|
3040
|
+
lesson_not_found: "Lesson not found.",
|
|
3041
|
+
module_not_found: "Module not found.",
|
|
3042
|
+
artifact_not_found: "Artifact not found.",
|
|
3043
|
+
bundle_not_found: "Bundle not found.",
|
|
3044
|
+
module_locked: "This module is not available yet.",
|
|
3045
|
+
signing_failed: "Could not sign the download URL. Try again in a moment.",
|
|
3046
|
+
invalid_json: "The server received a malformed request.",
|
|
3047
|
+
unauthorized: "You are not signed in. Run `10x auth` first.",
|
|
3048
|
+
no_membership: "No active course membership was found for this email.",
|
|
3049
|
+
invalid_refresh_token: "Your session has expired. Run `10x auth` again.",
|
|
3050
|
+
membership_revoked: "Your course membership has been revoked.",
|
|
3051
|
+
rate_limited: "Too many requests. Please slow down and try again shortly.",
|
|
3052
|
+
email_send_failed: "Could not send the login email. Try again in a moment.",
|
|
3053
|
+
admin_access_required: "This action requires admin access.",
|
|
3054
|
+
circle_api_error: "The membership service is temporarily unavailable.",
|
|
3055
|
+
internal_error: "The server hit an unexpected error."
|
|
3056
|
+
};
|
|
3057
|
+
function messageForApiError(payload) {
|
|
3058
|
+
if (!payload)
|
|
3059
|
+
return;
|
|
3060
|
+
if (typeof payload.message === "string" && payload.message.length > 0) {
|
|
3061
|
+
return payload.message;
|
|
3062
|
+
}
|
|
3063
|
+
if (typeof payload.error === "string" && payload.error.length > 0) {
|
|
3064
|
+
return ERROR_CODE_MESSAGES[payload.error];
|
|
3065
|
+
}
|
|
3066
|
+
return;
|
|
3067
|
+
}
|
|
3037
3068
|
async function request(method, path, body, options = {}) {
|
|
3038
3069
|
const base = resolveApiBase();
|
|
3039
3070
|
const url = path.startsWith("http") ? path : `${base}${path}`;
|
|
@@ -3077,11 +3108,22 @@ async function request(method, path, body, options = {}) {
|
|
|
3077
3108
|
}
|
|
3078
3109
|
if (!response.ok) {
|
|
3079
3110
|
const payload = parsed && typeof parsed === "object" ? parsed : undefined;
|
|
3111
|
+
const mapped = messageForApiError(payload);
|
|
3112
|
+
let errorMessage;
|
|
3113
|
+
if (mapped) {
|
|
3114
|
+
errorMessage = mapped;
|
|
3115
|
+
} else if (payload) {
|
|
3116
|
+
errorMessage = UNKNOWN_API_ERROR_MESSAGE;
|
|
3117
|
+
} else if (response.statusText.length > 0) {
|
|
3118
|
+
errorMessage = response.statusText;
|
|
3119
|
+
} else {
|
|
3120
|
+
errorMessage = UNKNOWN_API_ERROR_MESSAGE;
|
|
3121
|
+
}
|
|
3080
3122
|
return {
|
|
3081
3123
|
ok: false,
|
|
3082
3124
|
status: response.status,
|
|
3083
|
-
code: payload?.code
|
|
3084
|
-
error:
|
|
3125
|
+
code: typeof payload?.code === "string" ? payload.code : `http_${response.status}`,
|
|
3126
|
+
error: errorMessage,
|
|
3085
3127
|
payload
|
|
3086
3128
|
};
|
|
3087
3129
|
}
|