@shware/http 1.2.12 → 2.0.0

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.
@@ -25,16 +25,16 @@ __export(detail_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(detail_exports);
27
27
  var DetailType = /* @__PURE__ */ ((DetailType2) => {
28
- DetailType2["ERROR_INFO"] = "ERROR_INFO";
29
- DetailType2["RETRY_INFO"] = "RETRY_INFO";
30
- DetailType2["DEBUG_INFO"] = "DEBUG_INFO";
31
- DetailType2["QUOTA_FAILURE"] = "QUOTA_FAILURE";
32
- DetailType2["PRECONDITION_FAILURE"] = "PRECONDITION_FAILURE";
33
- DetailType2["BAD_REQUEST"] = "BAD_REQUEST";
34
- DetailType2["REQUEST_INFO"] = "REQUEST_INFO";
35
- DetailType2["RESOURCE_INFO"] = "RESOURCE_INFO";
36
- DetailType2["HELP"] = "HELP";
37
- DetailType2["LOCALIZED_MESSAGE"] = "LOCALIZED_MESSAGE";
28
+ DetailType2["ERROR_INFO"] = "type.googleapis.com/google.rpc.ErrorInfo";
29
+ DetailType2["RETRY_INFO"] = "type.googleapis.com/google.rpc.RetryInfo";
30
+ DetailType2["DEBUG_INFO"] = "type.googleapis.com/google.rpc.DebugInfo";
31
+ DetailType2["QUOTA_FAILURE"] = "type.googleapis.com/google.rpc.QuotaFailure";
32
+ DetailType2["PRECONDITION_FAILURE"] = "type.googleapis.com/google.rpc.PreconditionFailure";
33
+ DetailType2["BAD_REQUEST"] = "type.googleapis.com/google.rpc.BadRequest";
34
+ DetailType2["REQUEST_INFO"] = "type.googleapis.com/google.rpc.RequestInfo";
35
+ DetailType2["RESOURCE_INFO"] = "type.googleapis.com/google.rpc.ResourceInfo";
36
+ DetailType2["HELP"] = "type.googleapis.com/google.rpc.Help";
37
+ DetailType2["LOCALIZED_MESSAGE"] = "type.googleapis.com/google.rpc.LocalizedMessage";
38
38
  return DetailType2;
39
39
  })(DetailType || {});
40
40
  var Details = class _Details {
@@ -45,43 +45,43 @@ var Details = class _Details {
45
45
  return new _Details();
46
46
  }
47
47
  errorInfo(detail) {
48
- this.list.push({ type: "ERROR_INFO" /* ERROR_INFO */, ...detail });
48
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.ErrorInfo" /* ERROR_INFO */, ...detail });
49
49
  return this;
50
50
  }
51
51
  retryInfo(detail) {
52
- this.list.push({ type: "RETRY_INFO" /* RETRY_INFO */, ...detail });
52
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.RetryInfo" /* RETRY_INFO */, ...detail });
53
53
  return this;
54
54
  }
55
55
  debugInfo(detail) {
56
- this.list.push({ type: "DEBUG_INFO" /* DEBUG_INFO */, ...detail });
56
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.DebugInfo" /* DEBUG_INFO */, ...detail });
57
57
  return this;
58
58
  }
59
59
  quotaFailure(detail) {
60
- this.list.push({ type: "QUOTA_FAILURE" /* QUOTA_FAILURE */, ...detail });
60
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.QuotaFailure" /* QUOTA_FAILURE */, ...detail });
61
61
  return this;
62
62
  }
63
63
  preconditionFailure(detail) {
64
- this.list.push({ type: "PRECONDITION_FAILURE" /* PRECONDITION_FAILURE */, ...detail });
64
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.PreconditionFailure" /* PRECONDITION_FAILURE */, ...detail });
65
65
  return this;
66
66
  }
67
67
  badRequest(detail) {
68
- this.list.push({ type: "BAD_REQUEST" /* BAD_REQUEST */, ...detail });
68
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.BadRequest" /* BAD_REQUEST */, ...detail });
69
69
  return this;
70
70
  }
71
71
  requestInfo(detail) {
72
- this.list.push({ type: "REQUEST_INFO" /* REQUEST_INFO */, ...detail });
72
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.RequestInfo" /* REQUEST_INFO */, ...detail });
73
73
  return this;
74
74
  }
75
75
  resourceInfo(detail) {
76
- this.list.push({ type: "RESOURCE_INFO" /* RESOURCE_INFO */, ...detail });
76
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.ResourceInfo" /* RESOURCE_INFO */, ...detail });
77
77
  return this;
78
78
  }
79
79
  help(detail) {
80
- this.list.push({ type: "HELP" /* HELP */, ...detail });
80
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.Help" /* HELP */, ...detail });
81
81
  return this;
82
82
  }
83
83
  localizedMessage(detail) {
84
- this.list.push({ type: "LOCALIZED_MESSAGE" /* LOCALIZED_MESSAGE */, ...detail });
84
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.LocalizedMessage" /* LOCALIZED_MESSAGE */, ...detail });
85
85
  return this;
86
86
  }
87
87
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/error/detail.ts"],"sourcesContent":["import type { ErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'ERROR_INFO',\n RETRY_INFO = 'RETRY_INFO',\n DEBUG_INFO = 'DEBUG_INFO',\n QUOTA_FAILURE = 'QUOTA_FAILURE',\n PRECONDITION_FAILURE = 'PRECONDITION_FAILURE',\n BAD_REQUEST = 'BAD_REQUEST',\n REQUEST_INFO = 'REQUEST_INFO',\n RESOURCE_INFO = 'RESOURCE_INFO',\n HELP = 'HELP',\n LOCALIZED_MESSAGE = 'LOCALIZED_MESSAGE',\n}\n\nexport interface ErrorInfo {\n type: DetailType.ERROR_INFO;\n reason: keyof ErrorReason | (string & {});\n domain?: string;\n metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n type: DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n type: DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail?: string;\n}\n\nexport interface QuotaFailure {\n type: DetailType.QUOTA_FAILURE;\n violations: { subject: string; description: string }[];\n}\n\nexport interface PreconditionFailure {\n type: DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n type: DetailType.BAD_REQUEST;\n fieldViolations: { field: string; description: string }[];\n}\n\nexport interface RequestInfo {\n type: DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n type: DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n type: DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n type: DetailType.LOCALIZED_MESSAGE;\n locale: string;\n message: string;\n}\n\nexport type Detail =\n | RetryInfo\n | DebugInfo\n | QuotaFailure\n | ErrorInfo\n | PreconditionFailure\n | BadRequest\n | RequestInfo\n | ResourceInfo\n | Help\n | LocalizedMessage;\n\n/**\n * Example usage:\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n * */\nexport class Details {\n readonly list: Detail[] = [];\n private constructor() {}\n\n static new() {\n return new Details();\n }\n\n errorInfo(detail: Omit<ErrorInfo, 'type'>) {\n this.list.push({ type: DetailType.ERROR_INFO, ...detail });\n return this;\n }\n\n retryInfo(detail: Omit<RetryInfo, 'type'>) {\n this.list.push({ type: DetailType.RETRY_INFO, ...detail });\n return this;\n }\n\n debugInfo(detail: Omit<DebugInfo, 'type'>) {\n this.list.push({ type: DetailType.DEBUG_INFO, ...detail });\n return this;\n }\n\n quotaFailure(detail: Omit<QuotaFailure, 'type'>) {\n this.list.push({ type: DetailType.QUOTA_FAILURE, ...detail });\n return this;\n }\n\n preconditionFailure(detail: Omit<PreconditionFailure, 'type'>) {\n this.list.push({ type: DetailType.PRECONDITION_FAILURE, ...detail });\n return this;\n }\n\n badRequest(detail: Omit<BadRequest, 'type'>) {\n this.list.push({ type: DetailType.BAD_REQUEST, ...detail });\n return this;\n }\n\n requestInfo(detail: Omit<RequestInfo, 'type'>) {\n this.list.push({ type: DetailType.REQUEST_INFO, ...detail });\n return this;\n }\n\n resourceInfo(detail: Omit<ResourceInfo, 'type'>) {\n this.list.push({ type: DetailType.RESOURCE_INFO, ...detail });\n return this;\n }\n\n help(detail: Omit<Help, 'type'>) {\n this.list.push({ type: DetailType.HELP, ...detail });\n return this;\n }\n\n localizedMessage(detail: Omit<LocalizedMessage, 'type'>) {\n this.list.push({ type: DetailType.LOCALIZED_MESSAGE, ...detail });\n return this;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,0BAAuB;AACvB,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,kBAAe;AACf,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,uBAAoB;AAVV,SAAAA;AAAA,GAAA;AAyFL,IAAM,UAAN,MAAM,SAAQ;AAAA,EACV,OAAiB,CAAC;AAAA,EACnB,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAO,MAAM;AACX,WAAO,IAAI,SAAQ;AAAA,EACrB;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAoC;AAC/C,SAAK,KAAK,KAAK,EAAE,MAAM,qCAA0B,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,oBAAoB,QAA2C;AAC7D,SAAK,KAAK,KAAK,EAAE,MAAM,mDAAiC,GAAG,OAAO,CAAC;AACnE,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,QAAkC;AAC3C,SAAK,KAAK,KAAK,EAAE,MAAM,iCAAwB,GAAG,OAAO,CAAC;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,QAAmC;AAC7C,SAAK,KAAK,KAAK,EAAE,MAAM,mCAAyB,GAAG,OAAO,CAAC;AAC3D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAoC;AAC/C,SAAK,KAAK,KAAK,EAAE,MAAM,qCAA0B,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,QAA4B;AAC/B,SAAK,KAAK,KAAK,EAAE,MAAM,mBAAiB,GAAG,OAAO,CAAC;AACnD,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,QAAwC;AACvD,SAAK,KAAK,KAAK,EAAE,MAAM,6CAA8B,GAAG,OAAO,CAAC;AAChE,WAAO;AAAA,EACT;AACF;","names":["DetailType"]}
1
+ {"version":3,"sources":["../../src/error/detail.ts"],"sourcesContent":["/** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */\nimport type { ErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'type.googleapis.com/google.rpc.ErrorInfo',\n RETRY_INFO = 'type.googleapis.com/google.rpc.RetryInfo',\n DEBUG_INFO = 'type.googleapis.com/google.rpc.DebugInfo',\n QUOTA_FAILURE = 'type.googleapis.com/google.rpc.QuotaFailure',\n PRECONDITION_FAILURE = 'type.googleapis.com/google.rpc.PreconditionFailure',\n BAD_REQUEST = 'type.googleapis.com/google.rpc.BadRequest',\n REQUEST_INFO = 'type.googleapis.com/google.rpc.RequestInfo',\n RESOURCE_INFO = 'type.googleapis.com/google.rpc.ResourceInfo',\n HELP = 'type.googleapis.com/google.rpc.Help',\n LOCALIZED_MESSAGE = 'type.googleapis.com/google.rpc.LocalizedMessage',\n}\n\nexport interface ErrorInfo {\n '@type': DetailType.ERROR_INFO;\n reason: keyof ErrorReason | (string & {});\n domain?: string;\n metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n '@type': DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n '@type': DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail: string;\n}\n\nexport interface QuotaFailure {\n '@type': DetailType.QUOTA_FAILURE;\n violations: {\n subject: string;\n description: string;\n apiService: string;\n quoteId: string;\n quoteValue: number;\n quotaMetric: string;\n quotaDimensions: Record<string, string>;\n futureQuotaValue: number;\n }[];\n}\n\nexport interface PreconditionFailure {\n '@type': DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n '@type': DetailType.BAD_REQUEST;\n fieldViolations: {\n field: string;\n description: string;\n reason: string;\n localizedMessage: Omit<LocalizedMessage, '@type'>;\n }[];\n}\n\nexport interface RequestInfo {\n '@type': DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n '@type': DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n '@type': DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n '@type': DetailType.LOCALIZED_MESSAGE;\n locale: string;\n message: string;\n}\n\nexport type Detail =\n | RetryInfo\n | DebugInfo\n | QuotaFailure\n | ErrorInfo\n | PreconditionFailure\n | BadRequest\n | RequestInfo\n | ResourceInfo\n | Help\n | LocalizedMessage;\n\n/**\n * Example usage:\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n * */\nexport class Details {\n readonly list: Detail[] = [];\n private constructor() {}\n\n static new() {\n return new Details();\n }\n\n errorInfo(detail: Omit<ErrorInfo, '@type'>) {\n this.list.push({ '@type': DetailType.ERROR_INFO, ...detail });\n return this;\n }\n\n retryInfo(detail: Omit<RetryInfo, '@type'>) {\n this.list.push({ '@type': DetailType.RETRY_INFO, ...detail });\n return this;\n }\n\n debugInfo(detail: Omit<DebugInfo, '@type'>) {\n this.list.push({ '@type': DetailType.DEBUG_INFO, ...detail });\n return this;\n }\n\n quotaFailure(detail: Omit<QuotaFailure, '@type'>) {\n this.list.push({ '@type': DetailType.QUOTA_FAILURE, ...detail });\n return this;\n }\n\n preconditionFailure(detail: Omit<PreconditionFailure, '@type'>) {\n this.list.push({ '@type': DetailType.PRECONDITION_FAILURE, ...detail });\n return this;\n }\n\n badRequest(detail: Omit<BadRequest, '@type'>) {\n this.list.push({ '@type': DetailType.BAD_REQUEST, ...detail });\n return this;\n }\n\n requestInfo(detail: Omit<RequestInfo, '@type'>) {\n this.list.push({ '@type': DetailType.REQUEST_INFO, ...detail });\n return this;\n }\n\n resourceInfo(detail: Omit<ResourceInfo, '@type'>) {\n this.list.push({ '@type': DetailType.RESOURCE_INFO, ...detail });\n return this;\n }\n\n help(detail: Omit<Help, '@type'>) {\n this.list.push({ '@type': DetailType.HELP, ...detail });\n return this;\n }\n\n localizedMessage(detail: Omit<LocalizedMessage, '@type'>) {\n this.list.push({ '@type': DetailType.LOCALIZED_MESSAGE, ...detail });\n return this;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,0BAAuB;AACvB,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,kBAAe;AACf,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,uBAAoB;AAVV,SAAAA;AAAA,GAAA;AAuGL,IAAM,UAAN,MAAM,SAAQ;AAAA,EACV,OAAiB,CAAC;AAAA,EACnB,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAO,MAAM;AACX,WAAO,IAAI,SAAQ;AAAA,EACrB;AAAA,EAEA,UAAU,QAAkC;AAC1C,SAAK,KAAK,KAAK,EAAE,SAAS,6DAAuB,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAkC;AAC1C,SAAK,KAAK,KAAK,EAAE,SAAS,6DAAuB,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAkC;AAC1C,SAAK,KAAK,KAAK,EAAE,SAAS,6DAAuB,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAqC;AAChD,SAAK,KAAK,KAAK,EAAE,SAAS,mEAA0B,GAAG,OAAO,CAAC;AAC/D,WAAO;AAAA,EACT;AAAA,EAEA,oBAAoB,QAA4C;AAC9D,SAAK,KAAK,KAAK,EAAE,SAAS,iFAAiC,GAAG,OAAO,CAAC;AACtE,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,QAAmC;AAC5C,SAAK,KAAK,KAAK,EAAE,SAAS,+DAAwB,GAAG,OAAO,CAAC;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,QAAoC;AAC9C,SAAK,KAAK,KAAK,EAAE,SAAS,iEAAyB,GAAG,OAAO,CAAC;AAC9D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAqC;AAChD,SAAK,KAAK,KAAK,EAAE,SAAS,mEAA0B,GAAG,OAAO,CAAC;AAC/D,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,QAA6B;AAChC,SAAK,KAAK,KAAK,EAAE,SAAS,kDAAiB,GAAG,OAAO,CAAC;AACtD,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,QAAyC;AACxD,SAAK,KAAK,KAAK,EAAE,SAAS,2EAA8B,GAAG,OAAO,CAAC;AACnE,WAAO;AAAA,EACT;AACF;","names":["DetailType"]}
@@ -1,41 +1,49 @@
1
1
  import { ErrorReason } from './reason.cjs';
2
2
 
3
+ /** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */
4
+
3
5
  declare enum DetailType {
4
- ERROR_INFO = "ERROR_INFO",
5
- RETRY_INFO = "RETRY_INFO",
6
- DEBUG_INFO = "DEBUG_INFO",
7
- QUOTA_FAILURE = "QUOTA_FAILURE",
8
- PRECONDITION_FAILURE = "PRECONDITION_FAILURE",
9
- BAD_REQUEST = "BAD_REQUEST",
10
- REQUEST_INFO = "REQUEST_INFO",
11
- RESOURCE_INFO = "RESOURCE_INFO",
12
- HELP = "HELP",
13
- LOCALIZED_MESSAGE = "LOCALIZED_MESSAGE"
6
+ ERROR_INFO = "type.googleapis.com/google.rpc.ErrorInfo",
7
+ RETRY_INFO = "type.googleapis.com/google.rpc.RetryInfo",
8
+ DEBUG_INFO = "type.googleapis.com/google.rpc.DebugInfo",
9
+ QUOTA_FAILURE = "type.googleapis.com/google.rpc.QuotaFailure",
10
+ PRECONDITION_FAILURE = "type.googleapis.com/google.rpc.PreconditionFailure",
11
+ BAD_REQUEST = "type.googleapis.com/google.rpc.BadRequest",
12
+ REQUEST_INFO = "type.googleapis.com/google.rpc.RequestInfo",
13
+ RESOURCE_INFO = "type.googleapis.com/google.rpc.ResourceInfo",
14
+ HELP = "type.googleapis.com/google.rpc.Help",
15
+ LOCALIZED_MESSAGE = "type.googleapis.com/google.rpc.LocalizedMessage"
14
16
  }
15
17
  interface ErrorInfo {
16
- type: DetailType.ERROR_INFO;
18
+ '@type': DetailType.ERROR_INFO;
17
19
  reason: keyof ErrorReason | (string & {});
18
20
  domain?: string;
19
21
  metadata?: Record<string, string>;
20
22
  }
21
23
  interface RetryInfo {
22
- type: DetailType.RETRY_INFO;
24
+ '@type': DetailType.RETRY_INFO;
23
25
  retryDelay: number;
24
26
  }
25
27
  interface DebugInfo {
26
- type: DetailType.DEBUG_INFO;
28
+ '@type': DetailType.DEBUG_INFO;
27
29
  stackEntries: string[];
28
- detail?: string;
30
+ detail: string;
29
31
  }
30
32
  interface QuotaFailure {
31
- type: DetailType.QUOTA_FAILURE;
33
+ '@type': DetailType.QUOTA_FAILURE;
32
34
  violations: {
33
35
  subject: string;
34
36
  description: string;
37
+ apiService: string;
38
+ quoteId: string;
39
+ quoteValue: number;
40
+ quotaMetric: string;
41
+ quotaDimensions: Record<string, string>;
42
+ futureQuotaValue: number;
35
43
  }[];
36
44
  }
37
45
  interface PreconditionFailure {
38
- type: DetailType.PRECONDITION_FAILURE;
46
+ '@type': DetailType.PRECONDITION_FAILURE;
39
47
  violations: {
40
48
  type: string;
41
49
  subject: string;
@@ -43,33 +51,35 @@ interface PreconditionFailure {
43
51
  }[];
44
52
  }
45
53
  interface BadRequest {
46
- type: DetailType.BAD_REQUEST;
54
+ '@type': DetailType.BAD_REQUEST;
47
55
  fieldViolations: {
48
56
  field: string;
49
57
  description: string;
58
+ reason: string;
59
+ localizedMessage: Omit<LocalizedMessage, '@type'>;
50
60
  }[];
51
61
  }
52
62
  interface RequestInfo {
53
- type: DetailType.REQUEST_INFO;
63
+ '@type': DetailType.REQUEST_INFO;
54
64
  requestId: string;
55
65
  servingData: string;
56
66
  }
57
67
  interface ResourceInfo {
58
- type: DetailType.RESOURCE_INFO;
68
+ '@type': DetailType.RESOURCE_INFO;
59
69
  resourceType: string;
60
70
  resourceName: string;
61
71
  owner: string;
62
72
  description: string;
63
73
  }
64
74
  interface Help {
65
- type: DetailType.HELP;
75
+ '@type': DetailType.HELP;
66
76
  links: {
67
77
  url: string;
68
78
  description: string;
69
79
  }[];
70
80
  }
71
81
  interface LocalizedMessage {
72
- type: DetailType.LOCALIZED_MESSAGE;
82
+ '@type': DetailType.LOCALIZED_MESSAGE;
73
83
  locale: string;
74
84
  message: string;
75
85
  }
@@ -84,16 +94,16 @@ declare class Details {
84
94
  readonly list: Detail[];
85
95
  private constructor();
86
96
  static new(): Details;
87
- errorInfo(detail: Omit<ErrorInfo, 'type'>): this;
88
- retryInfo(detail: Omit<RetryInfo, 'type'>): this;
89
- debugInfo(detail: Omit<DebugInfo, 'type'>): this;
90
- quotaFailure(detail: Omit<QuotaFailure, 'type'>): this;
91
- preconditionFailure(detail: Omit<PreconditionFailure, 'type'>): this;
92
- badRequest(detail: Omit<BadRequest, 'type'>): this;
93
- requestInfo(detail: Omit<RequestInfo, 'type'>): this;
94
- resourceInfo(detail: Omit<ResourceInfo, 'type'>): this;
95
- help(detail: Omit<Help, 'type'>): this;
96
- localizedMessage(detail: Omit<LocalizedMessage, 'type'>): this;
97
+ errorInfo(detail: Omit<ErrorInfo, '@type'>): this;
98
+ retryInfo(detail: Omit<RetryInfo, '@type'>): this;
99
+ debugInfo(detail: Omit<DebugInfo, '@type'>): this;
100
+ quotaFailure(detail: Omit<QuotaFailure, '@type'>): this;
101
+ preconditionFailure(detail: Omit<PreconditionFailure, '@type'>): this;
102
+ badRequest(detail: Omit<BadRequest, '@type'>): this;
103
+ requestInfo(detail: Omit<RequestInfo, '@type'>): this;
104
+ resourceInfo(detail: Omit<ResourceInfo, '@type'>): this;
105
+ help(detail: Omit<Help, '@type'>): this;
106
+ localizedMessage(detail: Omit<LocalizedMessage, '@type'>): this;
97
107
  }
98
108
 
99
109
  export { type BadRequest, type DebugInfo, type Detail, DetailType, Details, type ErrorInfo, type Help, type LocalizedMessage, type PreconditionFailure, type QuotaFailure, type RequestInfo, type ResourceInfo, type RetryInfo };
@@ -1,41 +1,49 @@
1
1
  import { ErrorReason } from './reason.js';
2
2
 
3
+ /** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */
4
+
3
5
  declare enum DetailType {
4
- ERROR_INFO = "ERROR_INFO",
5
- RETRY_INFO = "RETRY_INFO",
6
- DEBUG_INFO = "DEBUG_INFO",
7
- QUOTA_FAILURE = "QUOTA_FAILURE",
8
- PRECONDITION_FAILURE = "PRECONDITION_FAILURE",
9
- BAD_REQUEST = "BAD_REQUEST",
10
- REQUEST_INFO = "REQUEST_INFO",
11
- RESOURCE_INFO = "RESOURCE_INFO",
12
- HELP = "HELP",
13
- LOCALIZED_MESSAGE = "LOCALIZED_MESSAGE"
6
+ ERROR_INFO = "type.googleapis.com/google.rpc.ErrorInfo",
7
+ RETRY_INFO = "type.googleapis.com/google.rpc.RetryInfo",
8
+ DEBUG_INFO = "type.googleapis.com/google.rpc.DebugInfo",
9
+ QUOTA_FAILURE = "type.googleapis.com/google.rpc.QuotaFailure",
10
+ PRECONDITION_FAILURE = "type.googleapis.com/google.rpc.PreconditionFailure",
11
+ BAD_REQUEST = "type.googleapis.com/google.rpc.BadRequest",
12
+ REQUEST_INFO = "type.googleapis.com/google.rpc.RequestInfo",
13
+ RESOURCE_INFO = "type.googleapis.com/google.rpc.ResourceInfo",
14
+ HELP = "type.googleapis.com/google.rpc.Help",
15
+ LOCALIZED_MESSAGE = "type.googleapis.com/google.rpc.LocalizedMessage"
14
16
  }
15
17
  interface ErrorInfo {
16
- type: DetailType.ERROR_INFO;
18
+ '@type': DetailType.ERROR_INFO;
17
19
  reason: keyof ErrorReason | (string & {});
18
20
  domain?: string;
19
21
  metadata?: Record<string, string>;
20
22
  }
21
23
  interface RetryInfo {
22
- type: DetailType.RETRY_INFO;
24
+ '@type': DetailType.RETRY_INFO;
23
25
  retryDelay: number;
24
26
  }
25
27
  interface DebugInfo {
26
- type: DetailType.DEBUG_INFO;
28
+ '@type': DetailType.DEBUG_INFO;
27
29
  stackEntries: string[];
28
- detail?: string;
30
+ detail: string;
29
31
  }
30
32
  interface QuotaFailure {
31
- type: DetailType.QUOTA_FAILURE;
33
+ '@type': DetailType.QUOTA_FAILURE;
32
34
  violations: {
33
35
  subject: string;
34
36
  description: string;
37
+ apiService: string;
38
+ quoteId: string;
39
+ quoteValue: number;
40
+ quotaMetric: string;
41
+ quotaDimensions: Record<string, string>;
42
+ futureQuotaValue: number;
35
43
  }[];
36
44
  }
37
45
  interface PreconditionFailure {
38
- type: DetailType.PRECONDITION_FAILURE;
46
+ '@type': DetailType.PRECONDITION_FAILURE;
39
47
  violations: {
40
48
  type: string;
41
49
  subject: string;
@@ -43,33 +51,35 @@ interface PreconditionFailure {
43
51
  }[];
44
52
  }
45
53
  interface BadRequest {
46
- type: DetailType.BAD_REQUEST;
54
+ '@type': DetailType.BAD_REQUEST;
47
55
  fieldViolations: {
48
56
  field: string;
49
57
  description: string;
58
+ reason: string;
59
+ localizedMessage: Omit<LocalizedMessage, '@type'>;
50
60
  }[];
51
61
  }
52
62
  interface RequestInfo {
53
- type: DetailType.REQUEST_INFO;
63
+ '@type': DetailType.REQUEST_INFO;
54
64
  requestId: string;
55
65
  servingData: string;
56
66
  }
57
67
  interface ResourceInfo {
58
- type: DetailType.RESOURCE_INFO;
68
+ '@type': DetailType.RESOURCE_INFO;
59
69
  resourceType: string;
60
70
  resourceName: string;
61
71
  owner: string;
62
72
  description: string;
63
73
  }
64
74
  interface Help {
65
- type: DetailType.HELP;
75
+ '@type': DetailType.HELP;
66
76
  links: {
67
77
  url: string;
68
78
  description: string;
69
79
  }[];
70
80
  }
71
81
  interface LocalizedMessage {
72
- type: DetailType.LOCALIZED_MESSAGE;
82
+ '@type': DetailType.LOCALIZED_MESSAGE;
73
83
  locale: string;
74
84
  message: string;
75
85
  }
@@ -84,16 +94,16 @@ declare class Details {
84
94
  readonly list: Detail[];
85
95
  private constructor();
86
96
  static new(): Details;
87
- errorInfo(detail: Omit<ErrorInfo, 'type'>): this;
88
- retryInfo(detail: Omit<RetryInfo, 'type'>): this;
89
- debugInfo(detail: Omit<DebugInfo, 'type'>): this;
90
- quotaFailure(detail: Omit<QuotaFailure, 'type'>): this;
91
- preconditionFailure(detail: Omit<PreconditionFailure, 'type'>): this;
92
- badRequest(detail: Omit<BadRequest, 'type'>): this;
93
- requestInfo(detail: Omit<RequestInfo, 'type'>): this;
94
- resourceInfo(detail: Omit<ResourceInfo, 'type'>): this;
95
- help(detail: Omit<Help, 'type'>): this;
96
- localizedMessage(detail: Omit<LocalizedMessage, 'type'>): this;
97
+ errorInfo(detail: Omit<ErrorInfo, '@type'>): this;
98
+ retryInfo(detail: Omit<RetryInfo, '@type'>): this;
99
+ debugInfo(detail: Omit<DebugInfo, '@type'>): this;
100
+ quotaFailure(detail: Omit<QuotaFailure, '@type'>): this;
101
+ preconditionFailure(detail: Omit<PreconditionFailure, '@type'>): this;
102
+ badRequest(detail: Omit<BadRequest, '@type'>): this;
103
+ requestInfo(detail: Omit<RequestInfo, '@type'>): this;
104
+ resourceInfo(detail: Omit<ResourceInfo, '@type'>): this;
105
+ help(detail: Omit<Help, '@type'>): this;
106
+ localizedMessage(detail: Omit<LocalizedMessage, '@type'>): this;
97
107
  }
98
108
 
99
109
  export { type BadRequest, type DebugInfo, type Detail, DetailType, Details, type ErrorInfo, type Help, type LocalizedMessage, type PreconditionFailure, type QuotaFailure, type RequestInfo, type ResourceInfo, type RetryInfo };
@@ -1,15 +1,15 @@
1
1
  // src/error/detail.ts
2
2
  var DetailType = /* @__PURE__ */ ((DetailType2) => {
3
- DetailType2["ERROR_INFO"] = "ERROR_INFO";
4
- DetailType2["RETRY_INFO"] = "RETRY_INFO";
5
- DetailType2["DEBUG_INFO"] = "DEBUG_INFO";
6
- DetailType2["QUOTA_FAILURE"] = "QUOTA_FAILURE";
7
- DetailType2["PRECONDITION_FAILURE"] = "PRECONDITION_FAILURE";
8
- DetailType2["BAD_REQUEST"] = "BAD_REQUEST";
9
- DetailType2["REQUEST_INFO"] = "REQUEST_INFO";
10
- DetailType2["RESOURCE_INFO"] = "RESOURCE_INFO";
11
- DetailType2["HELP"] = "HELP";
12
- DetailType2["LOCALIZED_MESSAGE"] = "LOCALIZED_MESSAGE";
3
+ DetailType2["ERROR_INFO"] = "type.googleapis.com/google.rpc.ErrorInfo";
4
+ DetailType2["RETRY_INFO"] = "type.googleapis.com/google.rpc.RetryInfo";
5
+ DetailType2["DEBUG_INFO"] = "type.googleapis.com/google.rpc.DebugInfo";
6
+ DetailType2["QUOTA_FAILURE"] = "type.googleapis.com/google.rpc.QuotaFailure";
7
+ DetailType2["PRECONDITION_FAILURE"] = "type.googleapis.com/google.rpc.PreconditionFailure";
8
+ DetailType2["BAD_REQUEST"] = "type.googleapis.com/google.rpc.BadRequest";
9
+ DetailType2["REQUEST_INFO"] = "type.googleapis.com/google.rpc.RequestInfo";
10
+ DetailType2["RESOURCE_INFO"] = "type.googleapis.com/google.rpc.ResourceInfo";
11
+ DetailType2["HELP"] = "type.googleapis.com/google.rpc.Help";
12
+ DetailType2["LOCALIZED_MESSAGE"] = "type.googleapis.com/google.rpc.LocalizedMessage";
13
13
  return DetailType2;
14
14
  })(DetailType || {});
15
15
  var Details = class _Details {
@@ -20,43 +20,43 @@ var Details = class _Details {
20
20
  return new _Details();
21
21
  }
22
22
  errorInfo(detail) {
23
- this.list.push({ type: "ERROR_INFO" /* ERROR_INFO */, ...detail });
23
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.ErrorInfo" /* ERROR_INFO */, ...detail });
24
24
  return this;
25
25
  }
26
26
  retryInfo(detail) {
27
- this.list.push({ type: "RETRY_INFO" /* RETRY_INFO */, ...detail });
27
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.RetryInfo" /* RETRY_INFO */, ...detail });
28
28
  return this;
29
29
  }
30
30
  debugInfo(detail) {
31
- this.list.push({ type: "DEBUG_INFO" /* DEBUG_INFO */, ...detail });
31
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.DebugInfo" /* DEBUG_INFO */, ...detail });
32
32
  return this;
33
33
  }
34
34
  quotaFailure(detail) {
35
- this.list.push({ type: "QUOTA_FAILURE" /* QUOTA_FAILURE */, ...detail });
35
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.QuotaFailure" /* QUOTA_FAILURE */, ...detail });
36
36
  return this;
37
37
  }
38
38
  preconditionFailure(detail) {
39
- this.list.push({ type: "PRECONDITION_FAILURE" /* PRECONDITION_FAILURE */, ...detail });
39
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.PreconditionFailure" /* PRECONDITION_FAILURE */, ...detail });
40
40
  return this;
41
41
  }
42
42
  badRequest(detail) {
43
- this.list.push({ type: "BAD_REQUEST" /* BAD_REQUEST */, ...detail });
43
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.BadRequest" /* BAD_REQUEST */, ...detail });
44
44
  return this;
45
45
  }
46
46
  requestInfo(detail) {
47
- this.list.push({ type: "REQUEST_INFO" /* REQUEST_INFO */, ...detail });
47
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.RequestInfo" /* REQUEST_INFO */, ...detail });
48
48
  return this;
49
49
  }
50
50
  resourceInfo(detail) {
51
- this.list.push({ type: "RESOURCE_INFO" /* RESOURCE_INFO */, ...detail });
51
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.ResourceInfo" /* RESOURCE_INFO */, ...detail });
52
52
  return this;
53
53
  }
54
54
  help(detail) {
55
- this.list.push({ type: "HELP" /* HELP */, ...detail });
55
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.Help" /* HELP */, ...detail });
56
56
  return this;
57
57
  }
58
58
  localizedMessage(detail) {
59
- this.list.push({ type: "LOCALIZED_MESSAGE" /* LOCALIZED_MESSAGE */, ...detail });
59
+ this.list.push({ "@type": "type.googleapis.com/google.rpc.LocalizedMessage" /* LOCALIZED_MESSAGE */, ...detail });
60
60
  return this;
61
61
  }
62
62
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/error/detail.ts"],"sourcesContent":["import type { ErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'ERROR_INFO',\n RETRY_INFO = 'RETRY_INFO',\n DEBUG_INFO = 'DEBUG_INFO',\n QUOTA_FAILURE = 'QUOTA_FAILURE',\n PRECONDITION_FAILURE = 'PRECONDITION_FAILURE',\n BAD_REQUEST = 'BAD_REQUEST',\n REQUEST_INFO = 'REQUEST_INFO',\n RESOURCE_INFO = 'RESOURCE_INFO',\n HELP = 'HELP',\n LOCALIZED_MESSAGE = 'LOCALIZED_MESSAGE',\n}\n\nexport interface ErrorInfo {\n type: DetailType.ERROR_INFO;\n reason: keyof ErrorReason | (string & {});\n domain?: string;\n metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n type: DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n type: DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail?: string;\n}\n\nexport interface QuotaFailure {\n type: DetailType.QUOTA_FAILURE;\n violations: { subject: string; description: string }[];\n}\n\nexport interface PreconditionFailure {\n type: DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n type: DetailType.BAD_REQUEST;\n fieldViolations: { field: string; description: string }[];\n}\n\nexport interface RequestInfo {\n type: DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n type: DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n type: DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n type: DetailType.LOCALIZED_MESSAGE;\n locale: string;\n message: string;\n}\n\nexport type Detail =\n | RetryInfo\n | DebugInfo\n | QuotaFailure\n | ErrorInfo\n | PreconditionFailure\n | BadRequest\n | RequestInfo\n | ResourceInfo\n | Help\n | LocalizedMessage;\n\n/**\n * Example usage:\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n * */\nexport class Details {\n readonly list: Detail[] = [];\n private constructor() {}\n\n static new() {\n return new Details();\n }\n\n errorInfo(detail: Omit<ErrorInfo, 'type'>) {\n this.list.push({ type: DetailType.ERROR_INFO, ...detail });\n return this;\n }\n\n retryInfo(detail: Omit<RetryInfo, 'type'>) {\n this.list.push({ type: DetailType.RETRY_INFO, ...detail });\n return this;\n }\n\n debugInfo(detail: Omit<DebugInfo, 'type'>) {\n this.list.push({ type: DetailType.DEBUG_INFO, ...detail });\n return this;\n }\n\n quotaFailure(detail: Omit<QuotaFailure, 'type'>) {\n this.list.push({ type: DetailType.QUOTA_FAILURE, ...detail });\n return this;\n }\n\n preconditionFailure(detail: Omit<PreconditionFailure, 'type'>) {\n this.list.push({ type: DetailType.PRECONDITION_FAILURE, ...detail });\n return this;\n }\n\n badRequest(detail: Omit<BadRequest, 'type'>) {\n this.list.push({ type: DetailType.BAD_REQUEST, ...detail });\n return this;\n }\n\n requestInfo(detail: Omit<RequestInfo, 'type'>) {\n this.list.push({ type: DetailType.REQUEST_INFO, ...detail });\n return this;\n }\n\n resourceInfo(detail: Omit<ResourceInfo, 'type'>) {\n this.list.push({ type: DetailType.RESOURCE_INFO, ...detail });\n return this;\n }\n\n help(detail: Omit<Help, 'type'>) {\n this.list.push({ type: DetailType.HELP, ...detail });\n return this;\n }\n\n localizedMessage(detail: Omit<LocalizedMessage, 'type'>) {\n this.list.push({ type: DetailType.LOCALIZED_MESSAGE, ...detail });\n return this;\n }\n}\n"],"mappings":";AAEO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,0BAAuB;AACvB,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,kBAAe;AACf,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,uBAAoB;AAVV,SAAAA;AAAA,GAAA;AAyFL,IAAM,UAAN,MAAM,SAAQ;AAAA,EACV,OAAiB,CAAC;AAAA,EACnB,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAO,MAAM;AACX,WAAO,IAAI,SAAQ;AAAA,EACrB;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAoC;AAC/C,SAAK,KAAK,KAAK,EAAE,MAAM,qCAA0B,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,oBAAoB,QAA2C;AAC7D,SAAK,KAAK,KAAK,EAAE,MAAM,mDAAiC,GAAG,OAAO,CAAC;AACnE,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,QAAkC;AAC3C,SAAK,KAAK,KAAK,EAAE,MAAM,iCAAwB,GAAG,OAAO,CAAC;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,QAAmC;AAC7C,SAAK,KAAK,KAAK,EAAE,MAAM,mCAAyB,GAAG,OAAO,CAAC;AAC3D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAoC;AAC/C,SAAK,KAAK,KAAK,EAAE,MAAM,qCAA0B,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,QAA4B;AAC/B,SAAK,KAAK,KAAK,EAAE,MAAM,mBAAiB,GAAG,OAAO,CAAC;AACnD,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,QAAwC;AACvD,SAAK,KAAK,KAAK,EAAE,MAAM,6CAA8B,GAAG,OAAO,CAAC;AAChE,WAAO;AAAA,EACT;AACF;","names":["DetailType"]}
1
+ {"version":3,"sources":["../../src/error/detail.ts"],"sourcesContent":["/** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */\nimport type { ErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'type.googleapis.com/google.rpc.ErrorInfo',\n RETRY_INFO = 'type.googleapis.com/google.rpc.RetryInfo',\n DEBUG_INFO = 'type.googleapis.com/google.rpc.DebugInfo',\n QUOTA_FAILURE = 'type.googleapis.com/google.rpc.QuotaFailure',\n PRECONDITION_FAILURE = 'type.googleapis.com/google.rpc.PreconditionFailure',\n BAD_REQUEST = 'type.googleapis.com/google.rpc.BadRequest',\n REQUEST_INFO = 'type.googleapis.com/google.rpc.RequestInfo',\n RESOURCE_INFO = 'type.googleapis.com/google.rpc.ResourceInfo',\n HELP = 'type.googleapis.com/google.rpc.Help',\n LOCALIZED_MESSAGE = 'type.googleapis.com/google.rpc.LocalizedMessage',\n}\n\nexport interface ErrorInfo {\n '@type': DetailType.ERROR_INFO;\n reason: keyof ErrorReason | (string & {});\n domain?: string;\n metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n '@type': DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n '@type': DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail: string;\n}\n\nexport interface QuotaFailure {\n '@type': DetailType.QUOTA_FAILURE;\n violations: {\n subject: string;\n description: string;\n apiService: string;\n quoteId: string;\n quoteValue: number;\n quotaMetric: string;\n quotaDimensions: Record<string, string>;\n futureQuotaValue: number;\n }[];\n}\n\nexport interface PreconditionFailure {\n '@type': DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n '@type': DetailType.BAD_REQUEST;\n fieldViolations: {\n field: string;\n description: string;\n reason: string;\n localizedMessage: Omit<LocalizedMessage, '@type'>;\n }[];\n}\n\nexport interface RequestInfo {\n '@type': DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n '@type': DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n '@type': DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n '@type': DetailType.LOCALIZED_MESSAGE;\n locale: string;\n message: string;\n}\n\nexport type Detail =\n | RetryInfo\n | DebugInfo\n | QuotaFailure\n | ErrorInfo\n | PreconditionFailure\n | BadRequest\n | RequestInfo\n | ResourceInfo\n | Help\n | LocalizedMessage;\n\n/**\n * Example usage:\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n * */\nexport class Details {\n readonly list: Detail[] = [];\n private constructor() {}\n\n static new() {\n return new Details();\n }\n\n errorInfo(detail: Omit<ErrorInfo, '@type'>) {\n this.list.push({ '@type': DetailType.ERROR_INFO, ...detail });\n return this;\n }\n\n retryInfo(detail: Omit<RetryInfo, '@type'>) {\n this.list.push({ '@type': DetailType.RETRY_INFO, ...detail });\n return this;\n }\n\n debugInfo(detail: Omit<DebugInfo, '@type'>) {\n this.list.push({ '@type': DetailType.DEBUG_INFO, ...detail });\n return this;\n }\n\n quotaFailure(detail: Omit<QuotaFailure, '@type'>) {\n this.list.push({ '@type': DetailType.QUOTA_FAILURE, ...detail });\n return this;\n }\n\n preconditionFailure(detail: Omit<PreconditionFailure, '@type'>) {\n this.list.push({ '@type': DetailType.PRECONDITION_FAILURE, ...detail });\n return this;\n }\n\n badRequest(detail: Omit<BadRequest, '@type'>) {\n this.list.push({ '@type': DetailType.BAD_REQUEST, ...detail });\n return this;\n }\n\n requestInfo(detail: Omit<RequestInfo, '@type'>) {\n this.list.push({ '@type': DetailType.REQUEST_INFO, ...detail });\n return this;\n }\n\n resourceInfo(detail: Omit<ResourceInfo, '@type'>) {\n this.list.push({ '@type': DetailType.RESOURCE_INFO, ...detail });\n return this;\n }\n\n help(detail: Omit<Help, '@type'>) {\n this.list.push({ '@type': DetailType.HELP, ...detail });\n return this;\n }\n\n localizedMessage(detail: Omit<LocalizedMessage, '@type'>) {\n this.list.push({ '@type': DetailType.LOCALIZED_MESSAGE, ...detail });\n return this;\n }\n}\n"],"mappings":";AAGO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,0BAAuB;AACvB,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,kBAAe;AACf,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,uBAAoB;AAVV,SAAAA;AAAA,GAAA;AAuGL,IAAM,UAAN,MAAM,SAAQ;AAAA,EACV,OAAiB,CAAC;AAAA,EACnB,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAO,MAAM;AACX,WAAO,IAAI,SAAQ;AAAA,EACrB;AAAA,EAEA,UAAU,QAAkC;AAC1C,SAAK,KAAK,KAAK,EAAE,SAAS,6DAAuB,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAkC;AAC1C,SAAK,KAAK,KAAK,EAAE,SAAS,6DAAuB,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAkC;AAC1C,SAAK,KAAK,KAAK,EAAE,SAAS,6DAAuB,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAqC;AAChD,SAAK,KAAK,KAAK,EAAE,SAAS,mEAA0B,GAAG,OAAO,CAAC;AAC/D,WAAO;AAAA,EACT;AAAA,EAEA,oBAAoB,QAA4C;AAC9D,SAAK,KAAK,KAAK,EAAE,SAAS,iFAAiC,GAAG,OAAO,CAAC;AACtE,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,QAAmC;AAC5C,SAAK,KAAK,KAAK,EAAE,SAAS,+DAAwB,GAAG,OAAO,CAAC;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,QAAoC;AAC9C,SAAK,KAAK,KAAK,EAAE,SAAS,iEAAyB,GAAG,OAAO,CAAC;AAC9D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAqC;AAChD,SAAK,KAAK,KAAK,EAAE,SAAS,mEAA0B,GAAG,OAAO,CAAC;AAC/D,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,QAA6B;AAChC,SAAK,KAAK,KAAK,EAAE,SAAS,kDAAiB,GAAG,OAAO,CAAC;AACtD,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,QAAyC;AACxD,SAAK,KAAK,KAAK,EAAE,SAAS,2EAA8B,GAAG,OAAO,CAAC;AACnE,WAAO;AAAA,EACT;AACF;","names":["DetailType"]}
@@ -20,20 +20,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/error/parse.ts
21
21
  var parse_exports = {};
22
22
  __export(parse_exports, {
23
- getErrorMessage: () => getErrorMessage
23
+ getErrorMessage: () => getErrorMessage,
24
+ getErrorReason: () => getErrorReason,
25
+ getFieldViolations: () => getFieldViolations
24
26
  });
25
27
  module.exports = __toCommonJS(parse_exports);
26
28
  var import_string = require("../utils/string.cjs");
27
29
  var import_detail = require("./detail.cjs");
30
+ function getErrorReason(data) {
31
+ if (typeof data !== "object" || data === null || !("error" in data)) return "UNKNOWN";
32
+ const { error } = data;
33
+ const errorInfo = error?.details?.find((d) => d["@type"] === import_detail.DetailType.ERROR_INFO);
34
+ return errorInfo?.reason ?? "UNKNOWN";
35
+ }
28
36
  function getErrorMessage(data, t) {
29
37
  if (typeof data !== "object" || data === null || !("error" in data)) {
30
38
  console.error("Unknown API error:", data);
31
39
  return { reason: "UNKNOWN", message: t("UNKNOWN") };
32
40
  }
33
41
  const { error } = data;
34
- const localizedMessage = error.details.find((d) => d.type === import_detail.DetailType.LOCALIZED_MESSAGE);
42
+ const localizedMessage = error?.details?.find((d) => d["@type"] === import_detail.DetailType.LOCALIZED_MESSAGE);
35
43
  if (localizedMessage) return { reason: "LOCALIZED_MESSAGE", message: localizedMessage.message };
36
- const errorInfo = error.details.find((d) => d.type === import_detail.DetailType.ERROR_INFO);
44
+ const errorInfo = error?.details?.find((d) => d["@type"] === import_detail.DetailType.ERROR_INFO);
37
45
  if (errorInfo) {
38
46
  return {
39
47
  reason: errorInfo.reason,
@@ -45,8 +53,16 @@ function getErrorMessage(data, t) {
45
53
  console.error("Unknown API error:", data);
46
54
  return { reason: "UNKNOWN", message: t("UNKNOWN") };
47
55
  }
56
+ function getFieldViolations(data) {
57
+ if (typeof data !== "object" || data === null || !("error" in data)) return [];
58
+ const { error } = data;
59
+ const badRequest = error?.details?.find((d) => d["@type"] === import_detail.DetailType.BAD_REQUEST);
60
+ return badRequest?.fieldViolations ?? [];
61
+ }
48
62
  // Annotate the CommonJS export names for ESM import in node:
49
63
  0 && (module.exports = {
50
- getErrorMessage
64
+ getErrorMessage,
65
+ getErrorReason,
66
+ getFieldViolations
51
67
  });
52
68
  //# sourceMappingURL=parse.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '../utils/string';\nimport { DetailType } from './detail';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: string; message: string } {\n // 0. unknown error\n if (typeof data !== 'object' || data === null || !('error' in data)) {\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n }\n\n const { error } = data as ErrorBody;\n\n // 1. from server via Accept-Language header or lng param\n const localizedMessage = error.details.find((d) => d.type === DetailType.LOCALIZED_MESSAGE);\n if (localizedMessage) return { reason: 'LOCALIZED_MESSAGE', message: localizedMessage.message };\n\n // 2. from business logic error\n const errorInfo = error.details.find((d) => d.type === DetailType.ERROR_INFO);\n if (errorInfo) {\n return {\n reason: errorInfo.reason,\n message: t(errorInfo.reason, errorInfo.metadata),\n };\n }\n\n // 3. error message in english\n if (hasText(error.message)) return { reason: 'ERROR_MESSAGE', message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: error.status, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAwB;AACxB,oBAA2B;AAYpB,SAAS,gBACd,MACA,GACqC;AAErC,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;AACnE,YAAQ,MAAM,sBAAsB,IAAI;AACxC,WAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AAAA,EACpD;AAEA,QAAM,EAAE,MAAM,IAAI;AAGlB,QAAM,mBAAmB,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,yBAAW,iBAAiB;AAC1F,MAAI,iBAAkB,QAAO,EAAE,QAAQ,qBAAqB,SAAS,iBAAiB,QAAQ;AAG9F,QAAM,YAAY,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,yBAAW,UAAU;AAC5E,MAAI,WAAW;AACb,WAAO;AAAA,MACL,QAAQ,UAAU;AAAA,MAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;AAAA,IACjD;AAAA,EACF;AAGA,UAAI,uBAAQ,MAAM,OAAO,EAAG,QAAO,EAAE,QAAQ,iBAAiB,SAAS,MAAM,QAAQ;AAGrF,MAAI,MAAM,OAAQ,QAAO,EAAE,QAAQ,MAAM,QAAQ,SAAS,EAAE,MAAM,MAAM,EAAE;AAG1E,UAAQ,MAAM,sBAAsB,IAAI;AACxC,SAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AACpD;","names":[]}
1
+ {"version":3,"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '../utils/string';\nimport { type BadRequest, DetailType } from './detail';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\n\nexport function getErrorReason(data: unknown) {\n if (typeof data !== 'object' || data === null || !('error' in data)) return 'UNKNOWN';\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo?.reason ?? 'UNKNOWN';\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: string; message: string } {\n // 0. unknown error\n if (typeof data !== 'object' || data === null || !('error' in data)) {\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n }\n\n const { error } = data as ErrorBody;\n\n // 1. from server via Accept-Language header or lng param\n const localizedMessage = error?.details?.find((d) => d['@type'] === DetailType.LOCALIZED_MESSAGE);\n if (localizedMessage) return { reason: 'LOCALIZED_MESSAGE', message: localizedMessage.message };\n\n // 2. from business logic error\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n if (errorInfo) {\n return {\n reason: errorInfo.reason,\n message: t(errorInfo.reason, errorInfo.metadata),\n };\n }\n\n // 3. error message in english\n if (hasText(error.message)) return { reason: 'ERROR_MESSAGE', message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: error.status, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAwB;AACxB,oBAA4C;AAIrC,SAAS,eAAe,MAAe;AAC5C,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO;AAC5E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW,UAAU;AAClF,SAAO,WAAW,UAAU;AAC9B;AAUO,SAAS,gBACd,MACA,GACqC;AAErC,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;AACnE,YAAQ,MAAM,sBAAsB,IAAI;AACxC,WAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AAAA,EACpD;AAEA,QAAM,EAAE,MAAM,IAAI;AAGlB,QAAM,mBAAmB,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW,iBAAiB;AAChG,MAAI,iBAAkB,QAAO,EAAE,QAAQ,qBAAqB,SAAS,iBAAiB,QAAQ;AAG9F,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW,UAAU;AAClF,MAAI,WAAW;AACb,WAAO;AAAA,MACL,QAAQ,UAAU;AAAA,MAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;AAAA,IACjD;AAAA,EACF;AAGA,UAAI,uBAAQ,MAAM,OAAO,EAAG,QAAO,EAAE,QAAQ,iBAAiB,SAAS,MAAM,QAAQ;AAGrF,MAAI,MAAM,OAAQ,QAAO,EAAE,QAAQ,MAAM,QAAQ,SAAS,EAAE,MAAM,MAAM,EAAE;AAG1E,UAAQ,MAAM,sBAAsB,IAAI;AACxC,SAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AACpD;AAWO,SAAS,mBAAmB,MAA8C;AAC/E,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO,CAAC;AAC7E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,aAAa,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW,WAAW;AACpF,SAAO,YAAY,mBAAmB,CAAC;AACzC;","names":[]}
@@ -1,5 +1,8 @@
1
+ import { NetworkErrorReason, StatusErrorReason, AuthenticationErrorReason, ModerationErrorReason, MultipartErrorReason, AppErrorReason } from './reason.cjs';
2
+ import { BadRequest } from './detail.cjs';
1
3
  import { Namespace, DefaultNamespace, TFunction } from 'i18next';
2
4
 
5
+ declare function getErrorReason(data: unknown): (string & {}) | keyof NetworkErrorReason | keyof StatusErrorReason | keyof AuthenticationErrorReason | keyof ModerationErrorReason | keyof MultipartErrorReason | keyof AppErrorReason;
3
6
  /**
4
7
  * @example For axios:
5
8
  *
@@ -12,5 +15,15 @@ declare function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefi
12
15
  reason: string;
13
16
  message: string;
14
17
  };
18
+ /**
19
+ * @example For react-hook-form:
20
+ *
21
+ * const { setError } = useForm();
22
+ * const fieldViolations = getFieldViolations(error.response.data);
23
+ * fieldViolations.forEach((violation) => {
24
+ * setError(violation.field, { message: violation.description });
25
+ * });
26
+ */
27
+ declare function getFieldViolations(data: unknown): BadRequest['fieldViolations'];
15
28
 
16
- export { getErrorMessage };
29
+ export { getErrorMessage, getErrorReason, getFieldViolations };
@@ -1,5 +1,8 @@
1
+ import { NetworkErrorReason, StatusErrorReason, AuthenticationErrorReason, ModerationErrorReason, MultipartErrorReason, AppErrorReason } from './reason.js';
2
+ import { BadRequest } from './detail.js';
1
3
  import { Namespace, DefaultNamespace, TFunction } from 'i18next';
2
4
 
5
+ declare function getErrorReason(data: unknown): (string & {}) | keyof NetworkErrorReason | keyof StatusErrorReason | keyof AuthenticationErrorReason | keyof ModerationErrorReason | keyof MultipartErrorReason | keyof AppErrorReason;
3
6
  /**
4
7
  * @example For axios:
5
8
  *
@@ -12,5 +15,15 @@ declare function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefi
12
15
  reason: string;
13
16
  message: string;
14
17
  };
18
+ /**
19
+ * @example For react-hook-form:
20
+ *
21
+ * const { setError } = useForm();
22
+ * const fieldViolations = getFieldViolations(error.response.data);
23
+ * fieldViolations.forEach((violation) => {
24
+ * setError(violation.field, { message: violation.description });
25
+ * });
26
+ */
27
+ declare function getFieldViolations(data: unknown): BadRequest['fieldViolations'];
15
28
 
16
- export { getErrorMessage };
29
+ export { getErrorMessage, getErrorReason, getFieldViolations };
@@ -1,15 +1,21 @@
1
1
  // src/error/parse.ts
2
2
  import { hasText } from "../utils/string.mjs";
3
3
  import { DetailType } from "./detail.mjs";
4
+ function getErrorReason(data) {
5
+ if (typeof data !== "object" || data === null || !("error" in data)) return "UNKNOWN";
6
+ const { error } = data;
7
+ const errorInfo = error?.details?.find((d) => d["@type"] === DetailType.ERROR_INFO);
8
+ return errorInfo?.reason ?? "UNKNOWN";
9
+ }
4
10
  function getErrorMessage(data, t) {
5
11
  if (typeof data !== "object" || data === null || !("error" in data)) {
6
12
  console.error("Unknown API error:", data);
7
13
  return { reason: "UNKNOWN", message: t("UNKNOWN") };
8
14
  }
9
15
  const { error } = data;
10
- const localizedMessage = error.details.find((d) => d.type === DetailType.LOCALIZED_MESSAGE);
16
+ const localizedMessage = error?.details?.find((d) => d["@type"] === DetailType.LOCALIZED_MESSAGE);
11
17
  if (localizedMessage) return { reason: "LOCALIZED_MESSAGE", message: localizedMessage.message };
12
- const errorInfo = error.details.find((d) => d.type === DetailType.ERROR_INFO);
18
+ const errorInfo = error?.details?.find((d) => d["@type"] === DetailType.ERROR_INFO);
13
19
  if (errorInfo) {
14
20
  return {
15
21
  reason: errorInfo.reason,
@@ -21,7 +27,15 @@ function getErrorMessage(data, t) {
21
27
  console.error("Unknown API error:", data);
22
28
  return { reason: "UNKNOWN", message: t("UNKNOWN") };
23
29
  }
30
+ function getFieldViolations(data) {
31
+ if (typeof data !== "object" || data === null || !("error" in data)) return [];
32
+ const { error } = data;
33
+ const badRequest = error?.details?.find((d) => d["@type"] === DetailType.BAD_REQUEST);
34
+ return badRequest?.fieldViolations ?? [];
35
+ }
24
36
  export {
25
- getErrorMessage
37
+ getErrorMessage,
38
+ getErrorReason,
39
+ getFieldViolations
26
40
  };
27
41
  //# sourceMappingURL=parse.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '../utils/string';\nimport { DetailType } from './detail';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: string; message: string } {\n // 0. unknown error\n if (typeof data !== 'object' || data === null || !('error' in data)) {\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n }\n\n const { error } = data as ErrorBody;\n\n // 1. from server via Accept-Language header or lng param\n const localizedMessage = error.details.find((d) => d.type === DetailType.LOCALIZED_MESSAGE);\n if (localizedMessage) return { reason: 'LOCALIZED_MESSAGE', message: localizedMessage.message };\n\n // 2. from business logic error\n const errorInfo = error.details.find((d) => d.type === DetailType.ERROR_INFO);\n if (errorInfo) {\n return {\n reason: errorInfo.reason,\n message: t(errorInfo.reason, errorInfo.metadata),\n };\n }\n\n // 3. error message in english\n if (hasText(error.message)) return { reason: 'ERROR_MESSAGE', message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: error.status, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAYpB,SAAS,gBACd,MACA,GACqC;AAErC,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;AACnE,YAAQ,MAAM,sBAAsB,IAAI;AACxC,WAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AAAA,EACpD;AAEA,QAAM,EAAE,MAAM,IAAI;AAGlB,QAAM,mBAAmB,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,WAAW,iBAAiB;AAC1F,MAAI,iBAAkB,QAAO,EAAE,QAAQ,qBAAqB,SAAS,iBAAiB,QAAQ;AAG9F,QAAM,YAAY,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,WAAW,UAAU;AAC5E,MAAI,WAAW;AACb,WAAO;AAAA,MACL,QAAQ,UAAU;AAAA,MAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;AAAA,IACjD;AAAA,EACF;AAGA,MAAI,QAAQ,MAAM,OAAO,EAAG,QAAO,EAAE,QAAQ,iBAAiB,SAAS,MAAM,QAAQ;AAGrF,MAAI,MAAM,OAAQ,QAAO,EAAE,QAAQ,MAAM,QAAQ,SAAS,EAAE,MAAM,MAAM,EAAE;AAG1E,UAAQ,MAAM,sBAAsB,IAAI;AACxC,SAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AACpD;","names":[]}
1
+ {"version":3,"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '../utils/string';\nimport { type BadRequest, DetailType } from './detail';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\n\nexport function getErrorReason(data: unknown) {\n if (typeof data !== 'object' || data === null || !('error' in data)) return 'UNKNOWN';\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo?.reason ?? 'UNKNOWN';\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: string; message: string } {\n // 0. unknown error\n if (typeof data !== 'object' || data === null || !('error' in data)) {\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n }\n\n const { error } = data as ErrorBody;\n\n // 1. from server via Accept-Language header or lng param\n const localizedMessage = error?.details?.find((d) => d['@type'] === DetailType.LOCALIZED_MESSAGE);\n if (localizedMessage) return { reason: 'LOCALIZED_MESSAGE', message: localizedMessage.message };\n\n // 2. from business logic error\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n if (errorInfo) {\n return {\n reason: errorInfo.reason,\n message: t(errorInfo.reason, errorInfo.metadata),\n };\n }\n\n // 3. error message in english\n if (hasText(error.message)) return { reason: 'ERROR_MESSAGE', message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: error.status, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAA0B,kBAAkB;AAIrC,SAAS,eAAe,MAAe;AAC5C,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO;AAC5E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,UAAU;AAClF,SAAO,WAAW,UAAU;AAC9B;AAUO,SAAS,gBACd,MACA,GACqC;AAErC,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;AACnE,YAAQ,MAAM,sBAAsB,IAAI;AACxC,WAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AAAA,EACpD;AAEA,QAAM,EAAE,MAAM,IAAI;AAGlB,QAAM,mBAAmB,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,iBAAiB;AAChG,MAAI,iBAAkB,QAAO,EAAE,QAAQ,qBAAqB,SAAS,iBAAiB,QAAQ;AAG9F,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,UAAU;AAClF,MAAI,WAAW;AACb,WAAO;AAAA,MACL,QAAQ,UAAU;AAAA,MAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;AAAA,IACjD;AAAA,EACF;AAGA,MAAI,QAAQ,MAAM,OAAO,EAAG,QAAO,EAAE,QAAQ,iBAAiB,SAAS,MAAM,QAAQ;AAGrF,MAAI,MAAM,OAAQ,QAAO,EAAE,QAAQ,MAAM,QAAQ,SAAS,EAAE,MAAM,MAAM,EAAE;AAG1E,UAAQ,MAAM,sBAAsB,IAAI;AACxC,SAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AACpD;AAWO,SAAS,mBAAmB,MAA8C;AAC/E,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO,CAAC;AAC7E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,aAAa,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,WAAW;AACpF,SAAO,YAAY,mBAAmB,CAAC;AACzC;","names":[]}
@@ -35,7 +35,9 @@ function errorHandler(error, c) {
35
35
  const details = import_detail.Details.new().requestInfo({ requestId, servingData });
36
36
  if (error instanceof import_status.StatusError) {
37
37
  error.body?.error?.details?.push(...details.list);
38
- const badRequest = error.body?.error?.details.find((d) => d.type === import_detail.DetailType.BAD_REQUEST);
38
+ const badRequest = error.body?.error?.details.find(
39
+ (d) => d["@type"] === import_detail.DetailType.BAD_REQUEST
40
+ );
39
41
  if (badRequest) console.warn(servingData, badRequest);
40
42
  return c.json(error.body, error.status);
41
43
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import { DetailType, Details } from '../error/detail';\nimport { Status, StatusError } from '../error/status';\nimport type { Context } from 'hono';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { Bindings, HTTPResponseError } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\n\nexport type Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\ntype AxiosError = {\n code?: string;\n cause?: unknown;\n status?: number;\n message?: string;\n isAxiosError: boolean;\n response?: {\n data: unknown;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n };\n config?: { url?: string; data?: unknown; method?: string; headers?: Record<string, string> };\n};\n\nexport function isAxiosError(payload: unknown): payload is AxiosError {\n return (\n payload !== null &&\n typeof payload === 'object' &&\n 'isAxiosError' in payload &&\n payload.isAxiosError === true\n );\n}\n\nexport function errorHandler<E extends Env = never>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n const badRequest = error.body?.error?.details.find((d) => d.type === DetailType.BAD_REQUEST);\n if (badRequest) console.warn(servingData, badRequest);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n if (isAxiosError(error)) {\n console.error({\n status: error.status,\n message: error.message,\n request: {\n method: error.config?.method,\n url: error.config?.url,\n data: error.config?.data,\n },\n response: { data: error.response?.data },\n });\n return Status.internal('Axios error').response(details);\n }\n\n console.error(`Unknown error: ${servingData}`, error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AACpC,oBAAoC;AA0B7B,SAAS,aAAa,SAAyC;AACpE,SACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEO,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,sBAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,2BAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,UAAM,aAAa,MAAM,MAAM,OAAO,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,yBAAW,WAAW;AAC3F,QAAI,WAAY,SAAQ,KAAK,aAAa,UAAU;AACpD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,qBAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK,GAAG;AACvB,YAAQ,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,QACP,QAAQ,MAAM,QAAQ;AAAA,QACtB,KAAK,MAAM,QAAQ;AAAA,QACnB,MAAM,MAAM,QAAQ;AAAA,MACtB;AAAA,MACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;AAAA,IACzC,CAAC;AACD,WAAO,qBAAO,SAAS,aAAa,EAAE,SAAS,OAAO;AAAA,EACxD;AAEA,UAAQ,MAAM,kBAAkB,WAAW,IAAI,KAAK;AACpD,SAAO,qBAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import { DetailType, Details } from '../error/detail';\nimport { Status, StatusError } from '../error/status';\nimport type { Context } from 'hono';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { Bindings, HTTPResponseError } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\n\nexport type Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\ntype AxiosError = {\n code?: string;\n cause?: unknown;\n status?: number;\n message?: string;\n isAxiosError: boolean;\n response?: {\n data: unknown;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n };\n config?: { url?: string; data?: unknown; method?: string; headers?: Record<string, string> };\n};\n\nexport function isAxiosError(payload: unknown): payload is AxiosError {\n return (\n payload !== null &&\n typeof payload === 'object' &&\n 'isAxiosError' in payload &&\n payload.isAxiosError === true\n );\n}\n\nexport function errorHandler<E extends Env = never>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n const badRequest = error.body?.error?.details.find(\n (d) => d['@type'] === DetailType.BAD_REQUEST\n );\n if (badRequest) console.warn(servingData, badRequest);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n if (isAxiosError(error)) {\n console.error({\n status: error.status,\n message: error.message,\n request: {\n method: error.config?.method,\n url: error.config?.url,\n data: error.config?.data,\n },\n response: { data: error.response?.data },\n });\n return Status.internal('Axios error').response(details);\n }\n\n console.error(`Unknown error: ${servingData}`, error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AACpC,oBAAoC;AA0B7B,SAAS,aAAa,SAAyC;AACpE,SACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEO,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,sBAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,2BAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,UAAM,aAAa,MAAM,MAAM,OAAO,QAAQ;AAAA,MAC5C,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW;AAAA,IACnC;AACA,QAAI,WAAY,SAAQ,KAAK,aAAa,UAAU;AACpD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,qBAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK,GAAG;AACvB,YAAQ,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,QACP,QAAQ,MAAM,QAAQ;AAAA,QACtB,KAAK,MAAM,QAAQ;AAAA,QACnB,MAAM,MAAM,QAAQ;AAAA,MACtB;AAAA,MACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;AAAA,IACzC,CAAC;AACD,WAAO,qBAAO,SAAS,aAAa,EAAE,SAAS,OAAO;AAAA,EACxD;AAEA,UAAQ,MAAM,kBAAkB,WAAW,IAAI,KAAK;AACpD,SAAO,qBAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
@@ -10,7 +10,9 @@ function errorHandler(error, c) {
10
10
  const details = Details.new().requestInfo({ requestId, servingData });
11
11
  if (error instanceof StatusError) {
12
12
  error.body?.error?.details?.push(...details.list);
13
- const badRequest = error.body?.error?.details.find((d) => d.type === DetailType.BAD_REQUEST);
13
+ const badRequest = error.body?.error?.details.find(
14
+ (d) => d["@type"] === DetailType.BAD_REQUEST
15
+ );
14
16
  if (badRequest) console.warn(servingData, badRequest);
15
17
  return c.json(error.body, error.status);
16
18
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import { DetailType, Details } from '../error/detail';\nimport { Status, StatusError } from '../error/status';\nimport type { Context } from 'hono';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { Bindings, HTTPResponseError } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\n\nexport type Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\ntype AxiosError = {\n code?: string;\n cause?: unknown;\n status?: number;\n message?: string;\n isAxiosError: boolean;\n response?: {\n data: unknown;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n };\n config?: { url?: string; data?: unknown; method?: string; headers?: Record<string, string> };\n};\n\nexport function isAxiosError(payload: unknown): payload is AxiosError {\n return (\n payload !== null &&\n typeof payload === 'object' &&\n 'isAxiosError' in payload &&\n payload.isAxiosError === true\n );\n}\n\nexport function errorHandler<E extends Env = never>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n const badRequest = error.body?.error?.details.find((d) => d.type === DetailType.BAD_REQUEST);\n if (badRequest) console.warn(servingData, badRequest);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n if (isAxiosError(error)) {\n console.error({\n status: error.status,\n message: error.message,\n request: {\n method: error.config?.method,\n url: error.config?.url,\n data: error.config?.data,\n },\n response: { data: error.response?.data },\n });\n return Status.internal('Axios error').response(details);\n }\n\n console.error(`Unknown error: ${servingData}`, error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";AAAA,SAAS,YAAY,eAAe;AACpC,SAAS,QAAQ,mBAAmB;AA0B7B,SAAS,aAAa,SAAyC;AACpE,SACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEO,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,QAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,aAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,UAAM,aAAa,MAAM,MAAM,OAAO,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,WAAW,WAAW;AAC3F,QAAI,WAAY,SAAQ,KAAK,aAAa,UAAU;AACpD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,OAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK,GAAG;AACvB,YAAQ,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,QACP,QAAQ,MAAM,QAAQ;AAAA,QACtB,KAAK,MAAM,QAAQ;AAAA,QACnB,MAAM,MAAM,QAAQ;AAAA,MACtB;AAAA,MACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;AAAA,IACzC,CAAC;AACD,WAAO,OAAO,SAAS,aAAa,EAAE,SAAS,OAAO;AAAA,EACxD;AAEA,UAAQ,MAAM,kBAAkB,WAAW,IAAI,KAAK;AACpD,SAAO,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import { DetailType, Details } from '../error/detail';\nimport { Status, StatusError } from '../error/status';\nimport type { Context } from 'hono';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { Bindings, HTTPResponseError } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\n\nexport type Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\ntype AxiosError = {\n code?: string;\n cause?: unknown;\n status?: number;\n message?: string;\n isAxiosError: boolean;\n response?: {\n data: unknown;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n };\n config?: { url?: string; data?: unknown; method?: string; headers?: Record<string, string> };\n};\n\nexport function isAxiosError(payload: unknown): payload is AxiosError {\n return (\n payload !== null &&\n typeof payload === 'object' &&\n 'isAxiosError' in payload &&\n payload.isAxiosError === true\n );\n}\n\nexport function errorHandler<E extends Env = never>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n const badRequest = error.body?.error?.details.find(\n (d) => d['@type'] === DetailType.BAD_REQUEST\n );\n if (badRequest) console.warn(servingData, badRequest);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n if (isAxiosError(error)) {\n console.error({\n status: error.status,\n message: error.message,\n request: {\n method: error.config?.method,\n url: error.config?.url,\n data: error.config?.data,\n },\n response: { data: error.response?.data },\n });\n return Status.internal('Axios error').response(details);\n }\n\n console.error(`Unknown error: ${servingData}`, error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";AAAA,SAAS,YAAY,eAAe;AACpC,SAAS,QAAQ,mBAAmB;AA0B7B,SAAS,aAAa,SAAyC;AACpE,SACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEO,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,QAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,aAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,UAAM,aAAa,MAAM,MAAM,OAAO,QAAQ;AAAA,MAC5C,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW;AAAA,IACnC;AACA,QAAI,WAAY,SAAQ,KAAK,aAAa,UAAU;AACpD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,OAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK,GAAG;AACvB,YAAQ,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,QACP,QAAQ,MAAM,QAAQ;AAAA,QACtB,KAAK,MAAM,QAAQ;AAAA,QACnB,MAAM,MAAM,QAAQ;AAAA,MACtB;AAAA,MACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;AAAA,IACzC,CAAC;AACD,WAAO,OAAO,SAAS,aAAa,EAAE,SAAS,OAAO;AAAA,EACxD;AAEA,UAAQ,MAAM,kBAAkB,WAAW,IAAI,KAAK;AACpD,SAAO,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
@@ -33,7 +33,12 @@ function zValidator(target, schema) {
33
33
  const result = await schema.safeParseAsync(value);
34
34
  if (result.success) return result.data;
35
35
  const fieldViolations = result.error.issues.map(
36
- ({ path, message }) => ({ field: path.join("."), description: message })
36
+ ({ code, path, message }) => ({
37
+ field: path.join("."),
38
+ description: message,
39
+ reason: code?.toUpperCase() ?? "INVALID_ARGUMENT",
40
+ localizedMessage: { locale: "en-US", message }
41
+ })
37
42
  );
38
43
  const details = import_detail.Details.new().badRequest({ fieldViolations });
39
44
  throw import_status.Status.invalidArgument().error(details);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import { validator } from 'hono/validator';\nimport { NEVER, pipe, string, transform } from 'zod/mini';\nimport { Details } from '../error/detail';\nimport { Status } from '../error/status';\nimport type { BadRequest } from '../error/detail';\nimport type { ValidationTargets } from 'hono';\nimport type { ZodType, output as outputV4 } from 'zod';\nimport type { ZodMiniType, output as outputMini } from 'zod/mini';\n\nexport function zValidator<S extends ZodType | ZodMiniType>(\n target: keyof ValidationTargets,\n schema: S\n) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as S extends ZodType ? outputV4<S> : outputMini<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n\nexport const bigintId = pipe(\n string(),\n transform((input, ctx) => {\n if (!/^(0|[1-9]\\d{0,19})$/.test(input)) {\n const message = `Invalid bigint id: ${input}`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n try {\n return BigInt(input);\n } catch {\n const message = `Parse bigint id: ${input} failed`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n })\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA0B;AAC1B,kBAA+C;AAC/C,oBAAwB;AACxB,oBAAuB;AAMhB,SAAS,WACd,QACA,QACA;AACA,aAAO,4BAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,sBAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,qBAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;AAEO,IAAM,eAAW;AAAA,MACtB,oBAAO;AAAA,MACP,uBAAU,CAAC,OAAO,QAAQ;AACxB,QAAI,CAAC,sBAAsB,KAAK,KAAK,GAAG;AACtC,YAAM,UAAU,sBAAsB,KAAK;AAC3C,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,OAAO,KAAK;AAAA,IACrB,QAAQ;AACN,YAAM,UAAU,oBAAoB,KAAK;AACzC,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import { validator } from 'hono/validator';\nimport { NEVER, pipe, string, transform } from 'zod/mini';\nimport { Details } from '../error/detail';\nimport { Status } from '../error/status';\nimport type { BadRequest } from '../error/detail';\nimport type { ValidationTargets } from 'hono';\nimport type { ZodType, output as outputV4 } from 'zod';\nimport type { ZodMiniType, output as outputMini } from 'zod/mini';\n\nexport function zValidator<S extends ZodType | ZodMiniType>(\n target: keyof ValidationTargets,\n schema: S\n) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as S extends ZodType ? outputV4<S> : outputMini<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ code, path, message }) => ({\n field: path.join('.'),\n description: message,\n reason: code?.toUpperCase() ?? 'INVALID_ARGUMENT',\n localizedMessage: { locale: 'en-US', message: message },\n })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n\nexport const bigintId = pipe(\n string(),\n transform((input, ctx) => {\n if (!/^(0|[1-9]\\d{0,19})$/.test(input)) {\n const message = `Invalid bigint id: ${input}`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n try {\n return BigInt(input);\n } catch {\n const message = `Parse bigint id: ${input} failed`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n })\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA0B;AAC1B,kBAA+C;AAC/C,oBAAwB;AACxB,oBAAuB;AAMhB,SAAS,WACd,QACA,QACA;AACA,aAAO,4BAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,MAAM,QAAQ,OAAO;AAAA,QAC5B,OAAO,KAAK,KAAK,GAAG;AAAA,QACpB,aAAa;AAAA,QACb,QAAQ,MAAM,YAAY,KAAK;AAAA,QAC/B,kBAAkB,EAAE,QAAQ,SAAS,QAAiB;AAAA,MACxD;AAAA,IACF;AACA,UAAM,UAAU,sBAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,qBAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;AAEO,IAAM,eAAW;AAAA,MACtB,oBAAO;AAAA,MACP,uBAAU,CAAC,OAAO,QAAQ;AACxB,QAAI,CAAC,sBAAsB,KAAK,KAAK,GAAG;AACtC,YAAM,UAAU,sBAAsB,KAAK;AAC3C,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,OAAO,KAAK;AAAA,IACrB,QAAQ;AACN,YAAM,UAAU,oBAAoB,KAAK;AACzC,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -8,7 +8,12 @@ function zValidator(target, schema) {
8
8
  const result = await schema.safeParseAsync(value);
9
9
  if (result.success) return result.data;
10
10
  const fieldViolations = result.error.issues.map(
11
- ({ path, message }) => ({ field: path.join("."), description: message })
11
+ ({ code, path, message }) => ({
12
+ field: path.join("."),
13
+ description: message,
14
+ reason: code?.toUpperCase() ?? "INVALID_ARGUMENT",
15
+ localizedMessage: { locale: "en-US", message }
16
+ })
12
17
  );
13
18
  const details = Details.new().badRequest({ fieldViolations });
14
19
  throw Status.invalidArgument().error(details);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import { validator } from 'hono/validator';\nimport { NEVER, pipe, string, transform } from 'zod/mini';\nimport { Details } from '../error/detail';\nimport { Status } from '../error/status';\nimport type { BadRequest } from '../error/detail';\nimport type { ValidationTargets } from 'hono';\nimport type { ZodType, output as outputV4 } from 'zod';\nimport type { ZodMiniType, output as outputMini } from 'zod/mini';\n\nexport function zValidator<S extends ZodType | ZodMiniType>(\n target: keyof ValidationTargets,\n schema: S\n) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as S extends ZodType ? outputV4<S> : outputMini<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n\nexport const bigintId = pipe(\n string(),\n transform((input, ctx) => {\n if (!/^(0|[1-9]\\d{0,19})$/.test(input)) {\n const message = `Invalid bigint id: ${input}`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n try {\n return BigInt(input);\n } catch {\n const message = `Parse bigint id: ${input} failed`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n })\n);\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,OAAO,MAAM,QAAQ,iBAAiB;AAC/C,SAAS,eAAe;AACxB,SAAS,cAAc;AAMhB,SAAS,WACd,QACA,QACA;AACA,SAAO,UAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,QAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,OAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;AAEO,IAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,UAAU,CAAC,OAAO,QAAQ;AACxB,QAAI,CAAC,sBAAsB,KAAK,KAAK,GAAG;AACtC,YAAM,UAAU,sBAAsB,KAAK;AAC3C,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,OAAO,KAAK;AAAA,IACrB,QAAQ;AACN,YAAM,UAAU,oBAAoB,KAAK;AACzC,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import { validator } from 'hono/validator';\nimport { NEVER, pipe, string, transform } from 'zod/mini';\nimport { Details } from '../error/detail';\nimport { Status } from '../error/status';\nimport type { BadRequest } from '../error/detail';\nimport type { ValidationTargets } from 'hono';\nimport type { ZodType, output as outputV4 } from 'zod';\nimport type { ZodMiniType, output as outputMini } from 'zod/mini';\n\nexport function zValidator<S extends ZodType | ZodMiniType>(\n target: keyof ValidationTargets,\n schema: S\n) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as S extends ZodType ? outputV4<S> : outputMini<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ code, path, message }) => ({\n field: path.join('.'),\n description: message,\n reason: code?.toUpperCase() ?? 'INVALID_ARGUMENT',\n localizedMessage: { locale: 'en-US', message: message },\n })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n\nexport const bigintId = pipe(\n string(),\n transform((input, ctx) => {\n if (!/^(0|[1-9]\\d{0,19})$/.test(input)) {\n const message = `Invalid bigint id: ${input}`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n try {\n return BigInt(input);\n } catch {\n const message = `Parse bigint id: ${input} failed`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n })\n);\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,OAAO,MAAM,QAAQ,iBAAiB;AAC/C,SAAS,eAAe;AACxB,SAAS,cAAc;AAMhB,SAAS,WACd,QACA,QACA;AACA,SAAO,UAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,MAAM,QAAQ,OAAO;AAAA,QAC5B,OAAO,KAAK,KAAK,GAAG;AAAA,QACpB,aAAa;AAAA,QACb,QAAQ,MAAM,YAAY,KAAK;AAAA,QAC/B,kBAAkB,EAAE,QAAQ,SAAS,QAAiB;AAAA,MACxD;AAAA,IACF;AACA,UAAM,UAAU,QAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,OAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;AAEO,IAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,UAAU,CAAC,OAAO,QAAQ;AACxB,QAAI,CAAC,sBAAsB,KAAK,KAAK,GAAG;AACtC,YAAM,UAAU,sBAAsB,KAAK;AAC3C,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,OAAO,KAAK;AAAA,IACrB,QAAQ;AACN,YAAM,UAAU,oBAAoB,KAAK;AACzC,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
package/dist/index.cjs CHANGED
@@ -17,7 +17,6 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
21
  // If the importer is in node compatibility mode or this is not an ESM
23
22
  // file that has been converted to a CommonJS file using a Babel-
@@ -33,16 +32,22 @@ var index_exports = {};
33
32
  __export(index_exports, {
34
33
  CheckoutCreateError: () => import_error.CheckoutCreateError,
35
34
  Cursor: () => import_response.Cursor,
35
+ DetailType: () => import_detail.DetailType,
36
+ Details: () => import_detail.Details,
36
37
  ISO_3601_1: () => import_iso_3601_1.ISO_3601_1,
37
38
  LoginCanceledError: () => import_error.LoginCanceledError,
38
39
  LoginTimeoutError: () => import_error.LoginTimeoutError,
39
40
  MAX_LENGTH: () => MAX_LENGTH,
40
41
  PurchaseError: () => import_error.PurchaseError,
42
+ Status: () => import_status.Status,
43
+ StatusError: () => import_status.StatusError,
41
44
  TokenBucket: () => import_token_bucket.TokenBucket,
42
45
  UidGenerator: () => import_snowflake.UidGenerator,
43
46
  base62: () => import_base62.base62,
44
47
  fetch: () => import_fetch.fetch,
45
48
  getErrorMessage: () => import_parse.getErrorMessage,
49
+ getErrorReason: () => import_parse.getErrorReason,
50
+ getFieldViolations: () => import_parse.getFieldViolations,
46
51
  getNextPageParam: () => import_response.getNextPageParam,
47
52
  getPreviousPageParam: () => import_response.getPreviousPageParam,
48
53
  hasText: () => import_string.hasText,
@@ -55,8 +60,8 @@ __export(index_exports, {
55
60
  });
56
61
  module.exports = __toCommonJS(index_exports);
57
62
  var import_error = require("./error/index.cjs");
58
- __reExport(index_exports, require("./error/detail.cjs"), module.exports);
59
- __reExport(index_exports, require("./error/status.cjs"), module.exports);
63
+ var import_detail = require("./error/detail.cjs");
64
+ var import_status = require("./error/status.cjs");
60
65
  var import_parse = require("./error/parse.cjs");
61
66
  var import_response = require("./response.cjs");
62
67
  var import_snowflake = require("./snowflake.cjs");
@@ -73,16 +78,22 @@ var import_iso_3601_1 = require("./iso/iso_3601_1.cjs");
73
78
  0 && (module.exports = {
74
79
  CheckoutCreateError,
75
80
  Cursor,
81
+ DetailType,
82
+ Details,
76
83
  ISO_3601_1,
77
84
  LoginCanceledError,
78
85
  LoginTimeoutError,
79
86
  MAX_LENGTH,
80
87
  PurchaseError,
88
+ Status,
89
+ StatusError,
81
90
  TokenBucket,
82
91
  UidGenerator,
83
92
  base62,
84
93
  fetch,
85
94
  getErrorMessage,
95
+ getErrorReason,
96
+ getFieldViolations,
86
97
  getNextPageParam,
87
98
  getPreviousPageParam,
88
99
  hasText,
@@ -91,8 +102,6 @@ var import_iso_3601_1 = require("./iso/iso_3601_1.cjs");
91
102
  once,
92
103
  pageParamsSchema,
93
104
  timing,
94
- uid,
95
- ...require("./error/detail.cjs"),
96
- ...require("./error/status.cjs")
105
+ uid
97
106
  });
98
107
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './error/reason';\nexport * from './error/detail';\nexport * from './error/status';\nexport { getErrorMessage } from './error/parse';\nexport {\n pageParamsSchema,\n Cursor,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { base62 } from './utils/base62';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { once } from './utils/promise';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\nexport { fetch, type RetryOptions } from './utils/fetch';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,mBAKO;AAUP,0BAAc,+BA5Bd;AA6BA,0BAAc,+BA7Bd;AA8BA,mBAAgC;AAChC,sBAMO;AAcP,uBAAkC;AAElC,iBAA4B;AAC5B,oBAAuB;AACvB,oBAAwB;AACxB,oBAAuB;AACvB,qBAAqB;AACrB,uBAA0B;AAC1B,0BAAqD;AACrD,mBAAyC;AACzC,wBAAoD;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorReason, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n pageParamsSchema,\n Cursor,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { base62 } from './utils/base62';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { once } from './utils/promise';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\nexport { fetch, type RetryOptions } from './utils/fetch';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,mBAKO;AAUP,oBAcO;AACP,oBAAoD;AACpD,mBAAoE;AACpE,sBAMO;AAcP,uBAAkC;AAElC,iBAA4B;AAC5B,oBAAuB;AACvB,oBAAwB;AACxB,oBAAuB;AACvB,qBAAqB;AACrB,uBAA0B;AAC1B,0BAAqD;AACrD,mBAAyC;AACzC,wBAAoD;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError } from './error/index.cjs';
2
2
  export { AppErrorReason, AuthenticationErrorReason, ErrorReason, ModerationErrorReason, MultipartErrorReason, NetworkErrorReason, StatusErrorReason } from './error/reason.cjs';
3
3
  export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure, RequestInfo, ResourceInfo, RetryInfo } from './error/detail.cjs';
4
- export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './error/status.cjs';
5
- export { getErrorMessage } from './error/parse.cjs';
4
+ export { ErrorBody, Status, StatusError } from './error/status.cjs';
5
+ export { getErrorMessage, getErrorReason, getFieldViolations } from './error/parse.cjs';
6
6
  export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, Page, PageParams, ParentPageParams, PrevParams, Response, getNextPageParam, getPreviousPageParam, initialPageParam, pageParamsSchema } from './response.cjs';
7
7
  export { UidGenerator, uid } from './snowflake.cjs';
8
8
  export { i as MAX_LENGTH } from './index-BnPgRQDl.cjs';
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError } from './error/index.js';
2
2
  export { AppErrorReason, AuthenticationErrorReason, ErrorReason, ModerationErrorReason, MultipartErrorReason, NetworkErrorReason, StatusErrorReason } from './error/reason.js';
3
3
  export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure, RequestInfo, ResourceInfo, RetryInfo } from './error/detail.js';
4
- export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './error/status.js';
5
- export { getErrorMessage } from './error/parse.js';
4
+ export { ErrorBody, Status, StatusError } from './error/status.js';
5
+ export { getErrorMessage, getErrorReason, getFieldViolations } from './error/parse.js';
6
6
  export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, Page, PageParams, ParentPageParams, PrevParams, Response, getNextPageParam, getPreviousPageParam, initialPageParam, pageParamsSchema } from './response.js';
7
7
  export { UidGenerator, uid } from './snowflake.js';
8
8
  export { i as MAX_LENGTH } from './index-BnPgRQDl.js';
package/dist/index.mjs CHANGED
@@ -5,9 +5,12 @@ import {
5
5
  CheckoutCreateError,
6
6
  PurchaseError
7
7
  } from "./error/index.mjs";
8
- export * from "./error/detail.mjs";
9
- export * from "./error/status.mjs";
10
- import { getErrorMessage } from "./error/parse.mjs";
8
+ import {
9
+ DetailType,
10
+ Details
11
+ } from "./error/detail.mjs";
12
+ import { Status, StatusError } from "./error/status.mjs";
13
+ import { getErrorReason, getErrorMessage, getFieldViolations } from "./error/parse.mjs";
11
14
  import {
12
15
  pageParamsSchema,
13
16
  Cursor,
@@ -28,16 +31,22 @@ import { ISO_3601_1 } from "./iso/iso_3601_1.mjs";
28
31
  export {
29
32
  CheckoutCreateError,
30
33
  Cursor,
34
+ DetailType,
35
+ Details,
31
36
  ISO_3601_1,
32
37
  LoginCanceledError,
33
38
  LoginTimeoutError,
34
39
  MAX_LENGTH,
35
40
  PurchaseError,
41
+ Status,
42
+ StatusError,
36
43
  TokenBucket,
37
44
  UidGenerator,
38
45
  base62,
39
46
  fetch,
40
47
  getErrorMessage,
48
+ getErrorReason,
49
+ getFieldViolations,
41
50
  getNextPageParam,
42
51
  getPreviousPageParam,
43
52
  hasText,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './error/reason';\nexport * from './error/detail';\nexport * from './error/status';\nexport { getErrorMessage } from './error/parse';\nexport {\n pageParamsSchema,\n Cursor,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { base62 } from './utils/base62';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { once } from './utils/promise';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\nexport { fetch, type RetryOptions } from './utils/fetch';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";AAaA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP,cAAc;AACd,cAAc;AACd,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcP,SAAS,cAAc,WAAW;AAElC,YAAY,gBAAgB;AAC5B,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,mBAA4C;AACrD,SAAS,aAAgC;AACzC,SAAS,kBAA2C;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorReason, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n pageParamsSchema,\n Cursor,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { base62 } from './utils/base62';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { once } from './utils/promise';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\nexport { fetch, type RetryOptions } from './utils/fetch';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";AAaA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP;AAAA,EACE;AAAA,EACA;AAAA,OAYK;AACP,SAAS,QAAQ,mBAAmC;AACpD,SAAS,gBAAgB,iBAAiB,0BAA0B;AACpE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcP,SAAS,cAAc,WAAW;AAElC,YAAY,gBAAgB;AAC5B,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,mBAA4C;AACrD,SAAS,aAAgC;AACzC,SAAS,kBAA2C;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "1.2.12",
3
+ "version": "2.0.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -40,15 +40,15 @@
40
40
  "devDependencies": {
41
41
  "@types/jest": "^30.0.0",
42
42
  "@types/node": "^24.10.1",
43
- "@types/react": "^19.2.5",
43
+ "@types/react": "^19.2.7",
44
44
  "jest": "^30.2.0",
45
45
  "ts-jest": "^29.4.5",
46
46
  "typescript": "^5.9.3",
47
- "@repo/eslint-config": "0.0.8",
47
+ "@repo/eslint-config": "0.0.9",
48
48
  "@repo/typescript-config": "0.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "zod": "^4.1.12"
51
+ "zod": "^4.1.13"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "hono": "^4.10.4",