Skip to content

Instantly share code, notes, and snippets.

View shlomisas's full-sized avatar
⚖️

Shlomi Sasson shlomisas

⚖️
  • Israel
View GitHub Profile
@shlomisas
shlomisas / windowErrorNotWorkingExample.js
Created June 9, 2021 21:13
window.onerror not working example
window.onerror = (message) => {
console.log(`in window.onerror: ${message}`);
};
new Promise((resolve, reject) => {
rj(new Error('some unhandeled promise rejection error'))
});
throw new Error('some regular error');
@shlomisas
shlomisas / js_sequence_vs_parallel.js
Last active May 10, 2021 06:17
js sequence vs. parallel
(async ()=> {
const TTL = 1000; // ms
const N = 4;
const foo = () => {
return new Promise((resolve, reject) => {
setTimeout(resolve, TTL);
});
}
javascript:angular.element(document.body).injector().get('$rootScope').$broadcast('player:controls:sfw:toggle')
@shlomisas
shlomisas / unchained-promise
Last active May 10, 2018 15:31
unchained-promise
(async() => {
try {
new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('something went wrong..'));
}, 0);
});
@shlomisas
shlomisas / low-priority-code-error-handling
Last active May 15, 2018 14:32
low-priority-code-error-handling
app.put('/user/:id', async(req, res, next) => {
try {
// Find a user model in the Database
const user = await User.findById(req.params.id);
if (!user) {
const e = new Error('User not found');
e.status = 404;
throw e;
@shlomisas
shlomisas / js-express-app-route-example
Last active May 15, 2018 14:18
js-express-app-route-example
app.get('/user/:id', async(req, res) => {
const user = await User.findById(req.params.id);
if (!user) {
const e = new Error('User not found');
e.status = 404;
throw e;
}
@shlomisas
shlomisas / js-express-app-route-error-handling
Last active May 15, 2018 14:18
js-express-app-route-error-handling
app.get('/', async(req, res, next) => {
try {
const model = await Model.findById(req.params.id);
res.json(model);
} catch (e) {
next(e);
}
});
@shlomisas
shlomisas / js-browser-app-event-listener-example
Last active May 15, 2018 14:17
js-browser-app-event-listener-example
$('#someButton').click(async evt => {
const userId = $(evt.target).attr('data-user-id');
const res = await axios.get(`/user/${userId}`);
// Assume that `render` function exists
render(res);
});
@shlomisas
shlomisas / js-browser-app-event-listener-error-handling
Last active May 15, 2018 14:18
js-browser-app-event-listener-error-handling
$('#someButton').click(async evt => {
try {
const userId = $(evt.target).attr('data-user-id');
const res = await axios.get(`/user/${userId}`);
// Assume that `render` function exists
render(res);
} catch (e) {
@shlomisas
shlomisas / js-app-main-error-handling-sync
Last active May 10, 2018 15:31
js-app-main-error-handling-sync
try {
const a = 1;
throw new Error('something went wrong..');
const b = 2;
} catch (e) {
console.error(e);