Skip to content

Instantly share code, notes, and snippets.

View diogomachado's full-sized avatar
🎯
Focusing

Diogo Machado diogomachado

🎯
Focusing
View GitHub Profile
@diogomachado
diogomachado / error-handling-with-fetch.md
Created January 17, 2021 15:18 — forked from odewahn/error-handling-with-fetch.md
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })
@diogomachado
diogomachado / .hyper.js
Created August 21, 2022 13:33
Hyperjs config
'use strict'
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
// default font size in pixels for all tabs

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@diogomachado
diogomachado / gist:2e4e60969e02a89bc8209cbb67f9f5ea
Created May 3, 2024 14:20
Alis with the command unix to clear node_modules
alias clearpackages="find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +"