UNPKG

@practica/create-node-app

Version:

Create Node.js app that is packed with best practices AND strive for simplicity

22 lines (19 loc) 521 B
import axios from 'axios'; import { AppError } from '@practica/error-handling'; export async function assertUserExists(userId: number) { const userVerificationRequest = await axios.get( `http://localhost/user/${userId}`, { validateStatus: () => true, } ); if (userVerificationRequest.status !== 200) { throw new AppError( 'user-doesnt-exist', `The user ${userId} doesnt exist`, userVerificationRequest.status, true ); } return userVerificationRequest.data; }