Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const assert = require('./lib/assert')
const vary = require('./lib/vary')
const cache = require('./lib/cache-control')

/** @type {typeof import('./types/index').fastifySensible} */
function fastifySensible (fastify, opts, next) {
fastify.decorate('httpErrors', httpErrors)
fastify.decorate('assert', assert)
Expand Down Expand Up @@ -68,6 +69,12 @@ function fastifySensible (fastify, opts, next) {
})
}

/**
* Wraps a promise for easier error handling without try/catch.
* @template T
* @param {Promise<T>} promise - The promise to wrap.
* @returns {Promise<[Error, undefined] | [null, T]>} A promise that resolves to a tuple containing either an error or the resolved data.
*/
function to (promise) {
return promise.then(data => [null, data], err => [err, undefined])
}
Expand Down
Loading