@mynthio/sdk 0.0.43 → 0.0.44

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/README.md CHANGED
@@ -874,7 +874,8 @@ try {
874
874
  console.log(task.urls);
875
875
  } catch (error) {
876
876
  if (error instanceof MynthAPIError) {
877
- console.error(error.status, error.code, error.message);
877
+ // `message` says what to fix. On a VALIDATION_ERROR, `issues` lists each invalid field.
878
+ console.error(error.status, error.code, error.message, error.issues);
878
879
  } else if (error instanceof TaskAsyncTimeoutError) {
879
880
  console.error("Task polling timed out");
880
881
  } else if (error instanceof TaskAsyncUnauthorizedError) {
package/dist/index.d.ts CHANGED
@@ -8,8 +8,18 @@ export declare class MynthAPIError extends Error {
8
8
  readonly status: number;
9
9
  /** Error code from the API response, if available */
10
10
  readonly code?: string | undefined;
11
- constructor(message: string, status: number, code?: string);
11
+ /**
12
+ * One entry per invalid field when `code` is `VALIDATION_ERROR` and the
13
+ * request failed its schema. `message` already states all of them.
14
+ */
15
+ readonly issues?: ReadonlyArray<MynthAPIErrorIssue> | undefined;
16
+ constructor(message: string, status: number, code?: string, issues?: ReadonlyArray<MynthAPIErrorIssue>);
12
17
  }
18
+ type MynthAPIErrorIssue = {
19
+ /** Where the problem is, e.g. `["size", "scale"]`. Empty for the body as a whole. */
20
+ path: ReadonlyArray<string | number>;
21
+ message: string;
22
+ };
13
23
  type MynthClientRequestOptions = {
14
24
  headers?: Record<string, string>;
15
25
  accessToken?: string | undefined;
@@ -787,4 +797,4 @@ declare class Mynth {
787
797
  get video(): MynthVideo;
788
798
  }
789
799
  //#endregion
790
- export { AVAILABLE_MODELS, AVAILABLE_VIDEO_MODELS, type AvailableModel, type AvailableVideoModel, type ModelCapability, Mynth, Mynth as default, MynthImage, type MynthModel, type MynthModelPricing, MynthModels, type MynthOptions, type MynthRequestOptions, type MynthSDKTypes, MynthVideo, type TaskAsyncAccess, type TaskAsyncWaitOptions, type VideoInputRole, type VideoResolutionTier };
800
+ export { AVAILABLE_MODELS, AVAILABLE_VIDEO_MODELS, type AvailableModel, type AvailableVideoModel, type ModelCapability, Mynth, Mynth as default, type MynthAPIErrorIssue, MynthImage, type MynthModel, type MynthModelPricing, MynthModels, type MynthOptions, type MynthRequestOptions, type MynthSDKTypes, MynthVideo, type TaskAsyncAccess, type TaskAsyncWaitOptions, type VideoInputRole, type VideoResolutionTier };
package/dist/index.js CHANGED
@@ -390,16 +390,30 @@ var MynthAPIError = class extends Error {
390
390
  status;
391
391
  /** Error code from the API response, if available */
392
392
  code;
393
- constructor(message, status, code) {
393
+ /**
394
+ * One entry per invalid field when `code` is `VALIDATION_ERROR` and the
395
+ * request failed its schema. `message` already states all of them.
396
+ */
397
+ issues;
398
+ constructor(message, status, code, issues) {
394
399
  super(message);
395
400
  this.name = "MynthAPIError";
396
401
  this.status = status;
397
402
  this.code = code;
403
+ this.issues = issues;
398
404
  }
399
405
  };
400
406
  function createApiError(data, status) {
401
- const errorResponse = data;
402
- return new MynthAPIError(errorResponse.error || errorResponse.message || `Request failed with status ${status}`, status, errorResponse.code);
407
+ const errorResponse = typeof data === "object" && data !== null ? data : {};
408
+ return new MynthAPIError(typeof errorResponse.message === "string" && errorResponse.message || typeof errorResponse.error === "string" && errorResponse.error || `Request failed with status ${status}`, status, typeof errorResponse.code === "string" ? errorResponse.code : void 0, Array.isArray(errorResponse.issues) ? errorResponse.issues : void 0);
409
+ }
410
+ /** An error body that is not JSON (a proxy's HTML page, say) still yields an API error. */
411
+ async function readErrorBody(response) {
412
+ try {
413
+ return await response.json();
414
+ } catch {
415
+ return;
416
+ }
403
417
  }
404
418
  /**
405
419
  * Internal HTTP client for making API requests.
@@ -431,9 +445,8 @@ var MynthClient = class {
431
445
  body: isFormData ? data : JSON.stringify(data),
432
446
  ...signal ? { signal } : {}
433
447
  });
434
- const json = await response.json();
435
- if (!response.ok) throw createApiError(json, response.status);
436
- return json;
448
+ if (!response.ok) throw createApiError(await readErrorBody(response), response.status);
449
+ return await response.json();
437
450
  }
438
451
  async get(path, { headers, accessToken, auth, signal } = {}) {
439
452
  const response = await fetch(this.getUrl(path), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mynthio/sdk",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
4
4
  "description": "Official Mynth SDK for image generation and analysis",
5
5
  "keywords": [
6
6
  "ai",