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 { Request, Response, NextFunction } from "express"; | |
| import { CustomError } from "../errors/custom-error"; | |
| export const errorHandler = ( | |
| err: Error, | |
| req: Request, | |
| res: Response, | |
| next: NextFunction | |
| ) => { |
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 { 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); | |
| } |
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 { 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); |
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 { 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); | |
| } |
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 abstract class CustomError extends Error { | |
| abstract statusCode: number; | |
| constructor(message: string) { | |
| super(message); | |
| Object.setPrototypeOf(this, CustomError.prototype); | |
| } | |
| abstract serializeError(): { message: string; field?: string }[]; | |
| } |
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
| { | |
| "email": "test", | |
| "password": "test" | |
| } |
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
| 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 = '.') |
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
| -- +goose Up | |
| CREATE TABLE post ( | |
| id int NOT NULL, | |
| title text, | |
| body text, | |
| PRIMARY KEY(id) | |
| ); | |
| -- +goose Down | |
| DROP TABLE post; |
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 { 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, | |
| ]; | |
| } |
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
| type User struct { | |
| firstName string `json:"first_name"` | |
| lastName string `json:"last_name"` | |
| } | |
| userObj = User{ | |
| firstName: "Arif", | |
| lastName: "Setyawan" | |
| } |
NewerOlder