Skip to content

Instantly share code, notes, and snippets.

View arifsetyawan's full-sized avatar

Arif Setyawan arifsetyawan

View GitHub Profile
import { Request, Response, NextFunction } from "express";
import { CustomError } from "../errors/custom-error";
export const errorHandler = (
err: Error,
req: Request,
res: Response,
next: NextFunction
) => {
import { CustomError } from "./custom-error";
export class BadRequestError extends CustomError {
statusCode = 400;
reason = 'something went wrong';
constructor(public message: string) {
super(message);
Object.setPrototypeOf(this, BadRequestError.prototype);
}
import { NextFunction, Request, Response } from "express";
import { validationResult } from "express-validator";
import { RequestValidationError } from "../errors/request-validation-error";
export const validateRequest = (
req: Request,
res: Response,
next: NextFunction
) => {
const errors = validationResult(req);
import { ValidationError } from "express-validator";
import { CustomError } from "./custom-error";
export class RequestValidationError extends CustomError {
statusCode = 400;
constructor(public errors: ValidationError[]) {
super('error validating request');
Object.setPrototypeOf(this, RequestValidationError.prototype);
}
export abstract class CustomError extends Error {
abstract statusCode: number;
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, CustomError.prototype);
}
abstract serializeError(): { message: string; field?: string }[];
}
{
"email": "test",
"password": "test"
}
@arifsetyawan
arifsetyawan / dwutube.py
Created October 7, 2021 13:56
Download Youtube Videos
from pytube import YouTube
url = "https://www.youtube.com/watch?v=hS9jaTweuPU"
video = YouTube(url)
stream = video.streams.get_highest_resolution()
stream.download(output_path = '.')
-- +goose Up
CREATE TABLE post (
id int NOT NULL,
title text,
body text,
PRIMARY KEY(id)
);
-- +goose Down
DROP TABLE post;
@arifsetyawan
arifsetyawan / abstract-unique-validator.ts
Created November 5, 2020 15:27 — forked from zarv1k/abstract-unique-validator.ts
Unique Validator Example for NestJS
import { ValidationArguments, ValidatorConstraintInterface } from 'class-validator';
import { Connection, EntitySchema, FindConditions, ObjectType } from 'typeorm';
interface UniqueValidationArguments<E> extends ValidationArguments {
constraints: [
ObjectType<E> | EntitySchema<E> | string,
((validationArguments: ValidationArguments) => FindConditions<E>) | keyof E,
];
}
@arifsetyawan
arifsetyawan / jsonmarshalunmarshal.go
Created December 29, 2019 07:44
Json Marshal and Unmarshal
type User struct {
firstName string `json:"first_name"`
lastName string `json:"last_name"`
}
userObj = User{
firstName: "Arif",
lastName: "Setyawan"
}