See how a minor change to your commit message style can make you a better programmer.
Format: <type>(<scope>): <subject>
<scope>
is optional
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
})
# Backup | |
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql | |
# Restore | |
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE | |
$("#search").keyup(function(){ | |
_this = this; | |
// Mostrando apenas as linhas que combinam e escondendo o restante | |
$.each($("#table tbody tr"), function() { | |
if($(this).text().toLowerCase().indexOf($(_this).val().toLowerCase()) === -1) | |
$(this).hide(); | |
else | |
$(this).show(); | |
}); | |
}); |
<?php | |
/** | |
* Classe que contem os métodos que iram | |
* filtrar as entradas enviadas via GET e POST | |
* | |
* @filesource | |
* @author Pedro Elsner <[email protected]> | |
* @license http://creativecommons.org/licenses/by/3.0/br/ Creative Commons 3.0 | |
* @abstract | |
* @version 1.0 |
// Somewhere in your controllers for this given example | |
// Example functions | |
$scope.itemOnLongPress = function(id) { | |
console.log('Long press'); | |
} | |
$scope.itemOnTouchEnd = function(id) { | |
console.log('Touch end'); | |
} |