<main>
	<div id="results">
		No results
	</div>
</main>
main {
	margin: 2em;
}

#results {
	font-weight: bold;
}

#results.happy {
	color: green;
}

#results.error {
	color: red;
}
View Compiled
function setResult( txt, cls ) {
	const r = document.getElementById( 'results' );
	r.innerText = txt;
	r.className = cls || '';
}

function showError( e ) {
	setResult( `error: ${ e }`, 'error' );
	// throw e;
	// return Promise.reject( e );
	// return 'error';
}

function showHappy( txt ) {
	setResult( `happy: ${ txt }`, 'happy' );
}

function showCatastrophe() {
	setResult( 'FAIL', 'error' );
}

Promise.reject( 'oh no' )
	.catch( showError )
	.then( showHappy )
	.catch( showCatastrophe );
View Compiled
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.