@typespec/ts-http-runtime 1.0.0-alpha.20231121.3 → 1.0.0-alpha.20231129.4

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.
@@ -2,14 +2,18 @@
2
2
  // Licensed under the MIT license.
3
3
  import { RestError } from "../restError";
4
4
  import { createHttpHeaders } from "../httpHeaders";
5
- /**
6
- * Creates a rest error from a PathUnchecked response
7
- */
8
- export function createRestError(message, response) {
5
+ export function createRestError(messageOrResponse, response) {
6
+ var _a;
7
+ const resp = typeof messageOrResponse === "string" ? response : messageOrResponse;
8
+ const internalError = resp.body.error || resp.body;
9
+ const message = typeof messageOrResponse === "string"
10
+ ? messageOrResponse
11
+ : (_a = internalError.message) !== null && _a !== void 0 ? _a : `Unexpected status code: ${resp.status}`;
9
12
  return new RestError(message, {
10
- statusCode: statusCodeToNumber(response.status),
11
- request: response.request,
12
- response: toPipelineResponse(response),
13
+ statusCode: statusCodeToNumber(resp.status),
14
+ code: internalError.code,
15
+ request: resp.request,
16
+ response: toPipelineResponse(resp),
13
17
  });
14
18
  }
15
19
  function toPipelineResponse(response) {
@@ -1 +1 @@
1
- {"version":3,"file":"restError.js","sourceRoot":"","sources":["../../../src/client/restError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,QAA+B;IAC9E,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;QAC5B,UAAU,EAAE,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC/C,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;KACvC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,QAA+B;;IACzD,OAAO;QACL,OAAO,EAAE,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,MAAA,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,mCAAI,CAAC,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AACnD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { PipelineResponse } from \"../interfaces\";\nimport { RestError } from \"../restError\";\nimport { createHttpHeaders } from \"../httpHeaders\";\nimport { PathUncheckedResponse } from \"./common\";\n\n/**\n * Creates a rest error from a PathUnchecked response\n */\nexport function createRestError(message: string, response: PathUncheckedResponse): RestError {\n return new RestError(message, {\n statusCode: statusCodeToNumber(response.status),\n request: response.request,\n response: toPipelineResponse(response),\n });\n}\n\nfunction toPipelineResponse(response: PathUncheckedResponse): PipelineResponse {\n return {\n headers: createHttpHeaders(response.headers),\n request: response.request,\n status: statusCodeToNumber(response.status) ?? -1,\n };\n}\n\nfunction statusCodeToNumber(statusCode: string): number | undefined {\n const status = Number.parseInt(statusCode);\n\n return Number.isNaN(status) ? undefined : status;\n}\n"]}
1
+ {"version":3,"file":"restError.js","sourceRoot":"","sources":["../../../src/client/restError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAWnD,MAAM,UAAU,eAAe,CAC7B,iBAAiD,EACjD,QAAgC;;IAEhC,MAAM,IAAI,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC;IACnF,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC;IACnD,MAAM,OAAO,GACX,OAAO,iBAAiB,KAAK,QAAQ;QACnC,CAAC,CAAC,iBAAiB;QACnB,CAAC,CAAC,MAAA,aAAa,CAAC,OAAO,mCAAI,2BAA2B,IAAI,CAAC,MAAM,EAAE,CAAC;IACxE,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;QAC5B,UAAU,EAAE,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3C,IAAI,EAAE,aAAa,CAAC,IAAI;QACxB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC;KACnC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,QAA+B;;IACzD,OAAO;QACL,OAAO,EAAE,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,MAAA,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,mCAAI,CAAC,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AACnD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { PipelineResponse } from \"../interfaces\";\nimport { RestError } from \"../restError\";\nimport { createHttpHeaders } from \"../httpHeaders\";\nimport { PathUncheckedResponse } from \"./common\";\n\n/**\n * Creates a rest error from a PathUnchecked response\n */\nexport function createRestError(response: PathUncheckedResponse): RestError;\n/**\n * Creates a rest error from an error message and a PathUnchecked response\n */\nexport function createRestError(message: string, response: PathUncheckedResponse): RestError;\nexport function createRestError(\n messageOrResponse: string | PathUncheckedResponse,\n response?: PathUncheckedResponse\n): RestError {\n const resp = typeof messageOrResponse === \"string\" ? response! : messageOrResponse;\n const internalError = resp.body.error || resp.body;\n const message =\n typeof messageOrResponse === \"string\"\n ? messageOrResponse\n : internalError.message ?? `Unexpected status code: ${resp.status}`;\n return new RestError(message, {\n statusCode: statusCodeToNumber(resp.status),\n code: internalError.code,\n request: resp.request,\n response: toPipelineResponse(resp),\n });\n}\n\nfunction toPipelineResponse(response: PathUncheckedResponse): PipelineResponse {\n return {\n headers: createHttpHeaders(response.headers),\n request: response.request,\n status: statusCodeToNumber(response.status) ?? -1,\n };\n}\n\nfunction statusCodeToNumber(statusCode: string): number | undefined {\n const status = Number.parseInt(statusCode);\n\n return Number.isNaN(status) ? undefined : status;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/ts-http-runtime",
3
- "version": "1.0.0-alpha.20231121.3",
3
+ "version": "1.0.0-alpha.20231129.4",
4
4
  "description": "Isomorphic client library for making HTTP requests in node.js and browser.",
5
5
  "sdk-type": "client",
6
6
  "main": "dist/index.js",
@@ -480,6 +480,11 @@ export declare function createPipelineRequest(options: PipelineRequestOptions):
480
480
  /**
481
481
  * Creates a rest error from a PathUnchecked response
482
482
  */
483
+ export declare function createRestError(response: PathUncheckedResponse): RestError;
484
+
485
+ /**
486
+ * Creates a rest error from an error message and a PathUnchecked response
487
+ */
483
488
  export declare function createRestError(message: string, response: PathUncheckedResponse): RestError;
484
489
 
485
490
  /**