This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let timer = null | |
export default (callback = () => {}, timing = 300) => { | |
if (timer) clearTimeout(timer) | |
timer = setTimeout(callback, timing) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default async ({ | |
promise, | |
onResponse = () => {}, | |
onLoad = () => {}, | |
onError = () => {}, | |
onComplete = () => {} | |
}) => { | |
onLoad(true) | |
try { | |
onResponse(await promise) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) |