Skip to content

Commit

Permalink
feat: 4.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorten committed Nov 21, 2021
1 parent 68ca046 commit bb10f6b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 deletions.
6 changes: 5 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# ChangeLog

## [4.7.1] - 21-11-2021

- feat: add `console.error` logging for errors thrown by provided app handler to help debugging.

## [4.7.0] - 21-11-2021

- feat: Support Deno `1.16.2` and std `0.115.1` and other deps upgrades
- feat: support Deno `1.16.2` and std `0.115.1` and other deps upgrades
- fix: improved `Server` determination

## [4.6.1] - 05-11-2021
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
SuperDeno is also available on [nest.land](https://nest.land/package/superdeno),
a package registry for Deno on the Blockchain.

> Note: All examples in this README are using the unversioned form of the import URL. In production you should always use the versioned import form such as `https://deno.land/x/superdeno@4.7.0/mod.ts`.
> Note: All examples in this README are using the unversioned form of the import URL. In production you should always use the versioned import form such as `https://deno.land/x/superdeno@4.7.1/mod.ts`.
## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ <h2>Installation</h2>
<p>SuperDeno is also available on <a href="https://nest.land/package/superdeno">nest.land</a>,
a package registry for Deno on the Blockchain.</p>
<blockquote>
<p>Note: All examples in this README are using the unversioned form of the import URL. In production you should always use the versioned import form such as <code>https://deno.land/x/superdeno@4.7.0/mod.ts</code>.</p>
<p>Note: All examples in this README are using the unversioned form of the import URL. In production you should always use the versioned import form such as <code>https://deno.land/x/superdeno@4.7.1/mod.ts</code>.</p>
</blockquote>
<a href="#example" id="example" style="color: inherit; text-decoration: none;">
<h2>Example</h2>
Expand Down
2 changes: 1 addition & 1 deletion egg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "superdeno",
"description": "HTTP assertions for Deno made easy via superagent.",
"version": "4.7.0",
"version": "4.7.1",
"repository": "https://github.com/asos-craigmorten/superdeno",
"stable": true,
"checkFormat": false,
Expand Down
4 changes: 2 additions & 2 deletions src/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export const close = async (

if (serverErr) {
console.error(
"SuperDeno experienced an unexpected server error",
"SuperDeno experienced an unexpected server error.",
serverErr,
);
}
if (error) {
console.error(
"SuperDeno experienced an unexpected error closing the server",
"SuperDeno experienced an unexpected error closing the server.",
error,
);
}
Expand Down
35 changes: 25 additions & 10 deletions src/superdeno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export interface SuperDeno {
unsubscribe(url: string): Test;
}

async function startManagedServer(
managedServer: Server,
app: RequestHandlerLike,
) {
try {
await managedServer.listenAndServe();
} catch (error) {
await close(managedServer, app, error);
}
}

/**
* Takes a a url string, [`http.Server`](https://doc.deno.land/https/deno.land/std/http/mod.ts#Server),
* a request handling function, or an object that implements an `app.listen()` method (which mirrors
Expand All @@ -66,11 +77,21 @@ export function superdeno(
const obj: Record<string, any> = {};

let managedServer: Server | undefined;

if (!isString(app) && !isListener(app) && !isServer(app)) {
managedServer = new Server({
addr: ":0",
handler(request) {
return app(request);
async handler(request) {
try {
return await app(request);
} catch (error) {
console.error(
"SuperDeno experienced an unexpected server error with the underlying app handler.",
error,
);

throw error;
}
},
});
}
Expand All @@ -87,14 +108,8 @@ export function superdeno(
};
});

if (isServer(managedServer)) {
(async () => {
try {
await managedServer.listenAndServe();
} catch (err) {
await close(managedServer, app, err);
}
})();
if (typeof managedServer !== "undefined") {
startManagedServer(managedServer, app as RequestHandlerLike);
}

return obj as SuperDeno;
Expand Down
8 changes: 4 additions & 4 deletions src/xhrSham.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ export class XMLHttpRequestSham {
this.statusText = "aborted";
};

xhr.setErrorResponse = function () {
const errorMessage = this.message;
xhr.setErrorResponse = function (error) {
const errorMessage = this.message ?? error.message;

// TODO: this needs work.
//
Expand Down Expand Up @@ -324,13 +324,13 @@ export class XMLHttpRequestSham {

return xhr.onreadystatechange();
}
} catch (_) {
} catch (error) {
// Error because it aborted
if (this.aborted) {
xhr.setAbortedResponse();
} else {
// Or genuine error
xhr.setErrorResponse();
xhr.setErrorResponse(error);
}

return xhr.onreadystatechange();
Expand Down
2 changes: 1 addition & 1 deletion version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Version of SuperDeno.
*/
export const VERSION = "4.7.0";
export const VERSION = "4.7.1";

/**
* Supported versions of Deno.
Expand Down

0 comments on commit bb10f6b

Please sign in to comment.