-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(adapter): take away error handling from adapters #1871
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9606173
feat(adapter): take away error handling from adapter
balazsorban44 fc684f9
Merge branch 'main' into feat/move-adapter-responsibility
balazsorban44 ad10af1
refactor: wrap getAdapter calls with error handler
balazsorban44 b0b5799
fix: correct adapterMethod
balazsorban44 d790e8e
build: more sane build targets
balazsorban44 dd4be24
feat(adapter): add built-in logging
balazsorban44 c1be7af
chore: revert version number
balazsorban44 3524264
chore: revert unnecessary file formatting
balazsorban44 a7e6d41
fix(ts): add displayName to AdapterInstance
balazsorban44 cd85314
fix: define logger in callback-handler
balazsorban44 6ec8ecc
fix(logger): pass logger to adapterErrorHandler
balazsorban44 b455975
Merge branch 'main' into feat/move-adapter-responsibility
balazsorban44 9f68463
Merge branch 'main' into feat/move-adapter-responsibility
balazsorban44 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// We aim to have the same support as Next.js | ||
// https://nextjs.org/docs/getting-started#system-requirements | ||
// https://nextjs.org/docs/basic-features/supported-browsers-features | ||
|
||
module.exports = { | ||
presets: [["@babel/preset-env", { targets: { node: "10.13" } }]], | ||
plugins: [ | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-transform-runtime", | ||
], | ||
comments: false, | ||
overrides: [ | ||
{ | ||
test: ["../src/client/**"], | ||
presets: [["@babel/preset-env", { targets: { ie: "11" } }]], | ||
}, | ||
{ | ||
test: ["../src/server/pages/**"], | ||
presets: ["preact"], | ||
}, | ||
], | ||
} |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { UnknownError } from "../lib/errors" | ||
|
||
/** | ||
* Handles adapter induced errors. | ||
* @param {import("types/adapters").AdapterInstance} adapter | ||
* @param {import("types").LoggerInstance} logger | ||
* @return {import("types/adapters").AdapterInstance} | ||
*/ | ||
export default function adapterErrorHandler(adapter, logger) { | ||
return Object.keys(adapter).reduce((acc, method) => { | ||
const name = capitalize(method) | ||
const code = upperSnake(name, adapter.displayName) | ||
|
||
const adapterMethod = adapter[method] | ||
acc[method] = async (...args) => { | ||
try { | ||
logger.debug(code, ...args) | ||
return await adapterMethod(...args) | ||
} catch (error) { | ||
logger.error(`${code}_ERROR`, error) | ||
const e = new UnknownError(error) | ||
e.name = `${name}Error` | ||
throw e | ||
} | ||
} | ||
return acc | ||
}, {}) | ||
} | ||
|
||
function capitalize(s) { | ||
return `${s[0].toUpperCase()}${s.slice(1)}` | ||
} | ||
|
||
function upperSnake(s, prefix = "ADAPTER") { | ||
return `${prefix}_${s.replace(/([A-Z])/g, "_$1")}`.toUpperCase() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should log out args with debug, and an adapter prefix(?)
@kripod, currently
logger.debug
is rewritten in adapters to include a prefix forcode
. Do you think we could return a name property next to getAdapter for this purpose?any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may specify an attribute like
{ displayName: string }
as the minimum requiredconfig
param when instantiating adapters. By doing so, we would also solve the typing issue ofAdapter(requiredParam, …)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After my recent commit, it will be possible for adapters to return a
displayName
property ingetAdapter
. Unfortunately we don't have the adapter configuration when we invoke the.getAdapter()
method.