MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / assertOk

Method assertOk

src.ts/utils/fetch.ts:935–956  ·  view source on GitHub ↗

* Throws a ``SERVER_ERROR`` if this response is not ok.

()

Source from the content-addressed store, hash-verified

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

Callers 4

#sendMethod · 0.45
_sendMethod · 0.45
fetchMethod · 0.45
_getAvatarMethod · 0.45

Calls 3

okMethod · 0.95
toUtf8StringFunction · 0.90
assertFunction · 0.90

Tested by

no test coverage detected