* Throws a ``SERVER_ERROR`` if this response is not ok.
()
| 933 | * Throws a ``SERVER_ERROR`` if this response is not ok. |
| 934 | */ |
| 935 | assertOk(): void { |
| 936 | if (this.ok()) { return; } |
| 937 | let { message, error } = this.#error; |
| 938 | if (message === "") { |
| 939 | message = `server response ${ this.statusCode } ${ this.statusMessage }`; |
| 940 | } |
| 941 | |
| 942 | let requestUrl: null | string = null; |
| 943 | if (this.request) { requestUrl = this.request.url; } |
| 944 | |
| 945 | let responseBody: null | string = null; |
| 946 | try { |
| 947 | if (this.#body) { responseBody = toUtf8String(this.#body); } |
| 948 | } catch (e) { } |
| 949 | |
| 950 | assert(false, message, "SERVER_ERROR", { |
| 951 | request: (this.request || "unknown request"), response: this, error, |
| 952 | info: { |
| 953 | requestUrl, responseBody, |
| 954 | responseStatus: `${ this.statusCode } ${ this.statusMessage }` } |
| 955 | }); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 |
no test coverage detected