1 define(["require", "exports", "../Core", "./Error"], function (require
, exports
, Core_1
, Error_1
) {
3 Object
.defineProperty(exports
, "__esModule", { value
: true });
4 exports
.apiResultFromStatusNotOk
= exports
.apiResultFromError
= exports
.apiResultFromValue
= void 0;
5 function apiResultFromValue(value
) {
14 exports
.apiResultFromValue
= apiResultFromValue
;
15 function apiResultFromError(error
) {
24 exports
.apiResultFromError
= apiResultFromError
;
25 async
function apiResultFromStatusNotOk(e
) {
26 const { response
} = e
;
27 if (response
=== undefined) {
28 // Aborted requests do not have a return value.
31 const contentType
= response
.headers
.get("content-type");
32 if (!contentType
|| !contentType
.includes("application/json")) {
37 json
= await response
.json();
42 if ((0, Core_1
.isPlainObject
)(json
) &&
43 Object
.hasOwn(json
, "type") &&
44 (json
.type
=== "api_error" || json
.type
=== "invalid_request_error") &&
45 typeof json
.code
=== "string" &&
46 typeof json
.message
=== "string" &&
47 typeof json
.param
=== "string") {
48 return apiResultFromError(new Error_1
.ApiError(json
.type
, json
.code
, json
.message
, json
.param
, response
.status
));
52 exports
.apiResultFromStatusNotOk
= apiResultFromStatusNotOk
;