James Gardner

JSON Stringify Error Object

Posted: Feb. 8, 2017, 7 p.m.

By default JSON.stringify gives an empty object for errors on node stable:

const error = new Error('Show this error please')
JSON.stringify({error: error})



But here's how you can encode it:

function replaceError(key, value) {
  if (value instanceof Error) {
    const error = {};
    Object.getOwnPropertyNames(value).forEach((key) => {
      error[key] = value[key];
    return error;
  return value;

function replaceErrorMessageOnly(key, value) {
  if (value instanceof Error) {
    return {message: value.message}
  return value;

Thanks: http://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify

GitHub Pages

Posted: Feb. 4, 2017, 11 a.m.

Set up an SSH key and a repo.

ssh-keygen -t rsa -b 4096 -C "james@exmaple.com"
# Choose jimmyg as the key name and add a password
mv jimmyg ~/.ssh/
mv jimmyg.pub ~/.ssh/
ssh-add ~/.ssh/jimmyg
cat ~/.ssh/jimmg.pub

Add the key in the GitHub settings.

Then for an ordinary repo at a path:

git init
git checkout -b gh-pages
git add .
git rm -r --cached .well-known/acme-challenge/
git status
git commit -m "Current"
git remote add origin git@github.com:thejimmyg/datacanspeak-site.git
git push origin gh-pages

Visit the site at https://thejimmyg.github.io/datacanspeak-site/

Then add a meta redirect template from the old site.

For a main organisation site:

git init
git add .
git rm -r --cached .well-known/acme-challenge/
git status
git commit -m "Current"
git remote add origin git@github.com:datacanspeak/datacanspeak.github.io.git
git push -u origin master

Then set the site custom domain to datacanspeak.com in the repo settings.

Make sure your A records are set up like this:

$ dig +noall +answer datacanspeak.com
datacanspeak.com. 73 IN A
datacanspeak.com. 73 IN A

Then you should be all sorted!

Meta Redirect Template

Posted: Feb. 4, 2017, 10 a.m.

    <title>Data Can Speak</title>
    <meta http-equiv="refresh" content="0; url=https://thejimmyg.github.io/datacanspeak-site/">
    <p>Redirecting to <a href="https://thejimmyg.github.io/datacanspeak-site/">https://thejimmyg.github.io/datacanspeak-site/</a> ...</p>

More posts »



All Years