Skip to content

Instantly share code, notes, and snippets.

@objectfoo
objectfoo / promises-async-await.js
Last active September 16, 2018 18:31
Explore when to throw vs reject
function asyncWork(options) {
let opt = options || {};
return new Promise((resolve, reject) => {
setTimeout(() => {
if (opt.error) {
const e = new Error(`An error has occured in "work ${opt.name}"`);
e.name = 'MyError';
// ERROR: throw is not caught by enclosing try catch

simple-oauth2#client-credentials-flow with retry requests

sequenceDiagram
	participant uiapp
	participant svc
	participant auth
	loop until success or 5
		uiapp->>svc: accessToken || null
 alt success

What do it do?

get-data-middleware

  • passes all set-cookie headers from responses that match provided or built in whitelist (__RequestVerificationToken) to browser
  • set default host for all requests
  • perform multiple middle-tier-client requests in parallel
  • set res.locals[key] for the result of each completed request
  • log success
const express = require('express');
const axios = require('axios');
const axiosRetry = require('axios-retry');
const R = require('ramda');
const uuidv4 = require('uuid/v4');
const router = express.Router();
const pkg = require('../package.json');
/**
* create instance of monolith GET machine
const axios = require('axios');
const axiosRetry = require('axios-retry');
const mapRequests = config => (req, res, next) => {
const requestKeys = Object.keys(config);
const outReqMap = requestKeys.reduce((reqMap, key) => {
const request = config[key];
reqMap[key] = request.ajaxFn();
---
name: Interests
description: Render subscribed interests and button to edit intrests
props:
rootPath: string
bootstrap:
token:
Name: __RequestVerificationtoken
Value: guid
state:
import * as R from 'ramda';
const getData = R.path(['Streams', 'Data']);
const pruneDataProps = R.pick([
'StreamId',
'ShortName',
'MemberCanChangeSubscription'
]);
const parse = R.compose(
R.map(pruneDataProps),
---
name: Interests
description: interests root component
---
available: []
props: null
state:
subscribed: []
error: null
methods: