Skip to content

Instantly share code, notes, and snippets.

View udara94's full-sized avatar
🎯
Focusing

Udara Abeythilake udara94

🎯
Focusing
View GitHub Profile
@Get()
@UseFilters(new HttpExceptionFilter())
getFuelForTokenHolders(){
throw new CustomFuelStationException('Fuel token is not valid', HttpStatus.UNAUTHORIZED)
}
import { ExceptionFilter, Catch, ArgumentsHost, HttpException } from '@nestjs/common';
import { Request, Response } from 'express';
@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter {
catch(exception: HttpException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const request = ctx.getRequest<Request>();
const status = exception.getStatus();
@Get('custom')
getFuelFromAvailableStations(){
throw new CustomFuelStationException('Fuel issue only for essential service', HttpStatus.FORBIDDEN)
}
export class CustomFuelStationException extends HttpException{
constructor(message: string, statusCode: number) {
super(message, statusCode);
}
}
@Get()
findAllAvailableFuelStations(){
throw new HttpException('No available fuel stations', HttpStatus.NOT_FOUND);
}
{
"statusCode": 500,
"message": "Internal server error"
}
export interface Movie {
id: string;
name: string;
rating: number;
year: number;
}
import { Controller, Get, HttpCode, HttpException, HttpStatus, Param } from '@nestjs/common';
import { STATUS_CODES } from 'http';
import { MoviesService } from './movies.service';
@Controller('movies')
export class MoviesController {
constructor(private moviesService: MoviesService) { }
@Get()
import { Injectable } from '@nestjs/common';
import { movies } from '../mock/movies';
import { Movie } from '../types/interfaces/movie';
@Injectable()
export class MoviesService {
private moviesList: Movie[];
constructor() {
this.moviesList = movies;
}
package com.example.myapplication;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;