
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
es-http-error
Advanced tools
HttpError class for browsers (without Node.js dependencies)
$ npm install es-http-error
throw new HttpError(404) // 'Not Found' as a default message
throw new HttpError(401, 'Unauthorized') // Custom Error Message
throw new HttpError(statusCodes.notFound); // Using with enums
Supported http status codes are here.
import HttpError, {statusCodes} from 'es-http-error'
main()
async function main (id) {
try {
// retrieve some data from API server
const res = await fetch('/api/something/great')
// check the response and throw an error if it's not ok
if (!res.ok) throw new HttpError(res.status)
// for example, render the view by lit-html
const render(view(await res.json()), document.body)
} catch (e) {
if (e instanceof HttpError) {
if (e.code === 401) logout() // check the code simply by number
if (e.code === statusCodes.notFound) notFound() // or via statusCodes
} else throw e
}
}
import HttpError, {statusCodes} from 'es-http-error/langs/ja'
try {
throw new HttpError(404)
} catch (e) {
console.log(e.message) // translated message "未検出"
}
Supported languages are listed here.
This library also provides a CommonJS vesion complementally.
Note: there's no support for i18n for CommonJS version.
const HttpError = require('es-http-error')
const {statusCodes} = HttpError
throw new HttpError(statusCodes.notFound)
There're some prior arts like below, but I couldn't find the one for browsers. So I made it.
util
....etc.
MIT
FAQs
HttpError class for browsers (without Node.js dependencies)
The npm package es-http-error receives a total of 5 weekly downloads. As such, es-http-error popularity was classified as not popular.
We found that es-http-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.