0.2.0 • Published 5 years ago
@peregrine/exceptions v0.2.0
@peregrine/exceptions
Library containing errors for HTTP, FileSystem operations and more
Setup
npm install --save @peregrine/exceptions
Examples
import { http } from "@peregrine/exceptions"
/**
* const exceptions = require("@peregrine/exceptions")
* const http = exceptions.http
*/
express.use('/api/v2/users/@me', (request, response, next) => {
next(new http.NotImplemented501Error("This endpoint is not implemented yet."))
})
this.express.use('*', (request, response, next) => {
next(new http.NotFound404Error('This endpoint does not exist.'))
})
express.use((error, request, response, next) => {
res.status(error.code || 500).json(error))
})
import { StringIndexOutOfBoundsException } from "@peregrine/exceptions"
export function getUppercasedCharacter(str: string, index: number){
if(index < 0 || index > str.length - 1){
throw new StringIndexOutOfBoundsException(`Index ${index} is ${index < 0 ? "smaller" : "greater"} than allowed: should be between 0 and ${str.length - 1}`)
}
return str.charAt(index).toUpperCase()
}
import { StringIndexOutOfBoundsException } from "@peregrine/exceptions"
export function getUppercasedCharacter(str: string, index: number){
if(index < 0 || index > str.length - 1){
throw new StringIndexOutOfBoundsException(`Index ${index} is ${index < 0 ? "smaller" : "greater"} than allowed: should be between 0 and ${str.length - 1}`)
}
return str.charAt(index).toUpperCase()
}
import { MethodNotImplementedException } from "@peregrine/exceptions"
export class WIPclass {
doSomething(): string | number {
throw new MethodNotImplementedException()
}
}