Skip to content

Instantly share code, notes, and snippets.

View LucasFsc's full-sized avatar
👨‍💻
Coding

Lucas Schlemper LucasFsc

👨‍💻
Coding
View GitHub Profile
@LucasFsc
LucasFsc / mongo-exception.filter.js
Created March 4, 2021 21:50
NestJS MongoError filter exception (Typescript)
import { Catch, ConflictException, ExceptionFilter } from '@nestjs/common'
import { MongoError } from 'mongodb'
@Catch(MongoError)
export class MongoExceptionFilter implements ExceptionFilter {
catch(exception: MongoError) {
switch (exception.code) {
case 11000:
// get error param key and value
const [key, value] = Object.entries({ ...exception }?.['keyValue'])?.[0]
@LucasFsc
LucasFsc / debounce.js
Created August 29, 2020 19:32
Debounce JS
let timer = null
export default (callback = () => {}, timing = 300) => {
if (timer) clearTimeout(timer)
timer = setTimeout(callback, timing)
}
@LucasFsc
LucasFsc / tryAwait.js
Created August 12, 2020 17:39
Promise async try catch util
export default async ({
promise,
onResponse = () => {},
onLoad = () => {},
onError = () => {},
onComplete = () => {}
}) => {
onLoad(true)
try {
onResponse(await promise)
@LucasFsc
LucasFsc / store.js
Created June 22, 2020 15:43
A simple function for RN to help with AsyncStorage
import AsyncStorage from '@react-native-community/async-storage'
export default key => ({
set: payload => AsyncStorage.setItem(key, JSON.stringify(payload)),
get: async () => {
const _ = AsyncStorage.getItem(key)
return _ ? JSON.parse(_) : null
},
remove: () => AsyncStorage.removeItem(key)
})