@blockfrost/blockfrost-utils
Advanced tools
Comparing version 1.0.0-alfa.4 to 1.0.0-alfa.5
/// <reference types="node" /> | ||
import type { FastifyError, FastifyRequest, FastifyReply } from 'fastify'; | ||
declare type FastifyErrorWithStatusCode = FastifyError & { | ||
statusCode: NonNullable<FastifyError['statusCode']>; | ||
}; | ||
export declare const notFoundHandler: (_request: FastifyRequest, reply: FastifyReply) => FastifyReply; | ||
@@ -13,2 +16,4 @@ export declare const errorHandler: (error: FastifyError, request: FastifyRequest, reply: FastifyReply) => FastifyReply; | ||
export declare const handle500: (reply: FastifyReply, error: unknown, request: FastifyRequest) => FastifyReply; | ||
export declare const handleFastifyError: (reply: FastifyReply, error: FastifyErrorWithStatusCode) => FastifyReply; | ||
export declare const handleInvalidAddress: (reply: FastifyReply) => FastifyReply<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify/types/route").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleInvalidAddress = exports.handle500 = exports.handle415 = exports.handle404 = exports.handle403Custom = exports.handle403 = exports.handle402 = exports.handle400Custom = exports.handle400 = exports.errorHandler = exports.notFoundHandler = void 0; | ||
exports.handleInvalidAddress = exports.handleFastifyError = exports.handle500 = exports.handle415 = exports.handle404 = exports.handle403Custom = exports.handle403 = exports.handle402 = exports.handle400Custom = exports.handle400 = exports.errorHandler = exports.notFoundHandler = void 0; | ||
const notFoundHandler = (_request, reply) => { | ||
@@ -32,3 +32,7 @@ return reply | ||
} | ||
// Fallback and handling of generic js errors | ||
if (error.statusCode !== undefined) { | ||
// Handle other Fastify errors with statusCode | ||
return (0, exports.handleFastifyError)(reply, error); | ||
} | ||
// Handle generic js errors | ||
return (0, exports.handle500)(reply, error, request); | ||
@@ -114,2 +118,12 @@ }; | ||
exports.handle500 = handle500; | ||
const handleFastifyError = (reply, error) => reply | ||
.code(error.statusCode) | ||
.header('Content-Type', 'application/json; charset=utf-8') | ||
.send({ | ||
// error.name is always "FastifyError", use error.code to provide more info to a client (eg. FST_ERR_CTP_INVALID_MEDIA_TYPE) | ||
error: error.name, | ||
message: error.message, | ||
status_code: error.statusCode, | ||
}); | ||
exports.handleFastifyError = handleFastifyError; | ||
const handleInvalidAddress = (reply) => { | ||
@@ -116,0 +130,0 @@ return (0, exports.handle400Custom)(reply, 'Invalid address for this network or malformed address format.'); |
{ | ||
"name": "@blockfrost/blockfrost-utils", | ||
"version": "1.0.0-alfa.4", | ||
"version": "1.0.0-alfa.5", | ||
"repository": "git@github.com:blockfrost/blockfrost-utils.git", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44712
769