Skip to content

Instantly share code, notes, and snippets.

@timfulmer
timfulmer / promise-errorhandling.js
Last active August 21, 2017 21:09
Promises and error handling
'use strict';
function promiseThatThrows(){
return new Promise((resolve,reject) => {
throw new Error('!!This needs to be handled!!');
});
}
function correctNestedErrorHandling(){
return new Promise((resolve,reject) => {
var express=require('express'),
mongoose=require('mongoose'),
bodyParser=require('body-parser'),
app=express(),
WidgetSchema=new mongoose.Schema({
name:{type:String,required:true},
status:{type:Boolean}
}
),
Widget=mongoose.model('Widget',WidgetSchema);
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script id="entry-template" type="text/x-handlebars-template">
<div class="entry">
<h1>{{name}}</h1>
<div class="body">
weather: {{weather.0.description}}
</div>
</div>