Skip to content

Instantly share code, notes, and snippets.

View meredian's full-sized avatar
🦆
Because ducks can!

Anton Sidelnikov meredian

🦆
Because ducks can!
View GitHub Profile
@meredian
meredian / proxyWrapper.spec.js
Created May 14, 2020 17:48
ProxyWrapper to catch data changes - almost full spec, good for TDD approach :) Missing details is "Minimal subtree in diffs" on update requirement, but it's already complex enough.
const assert = require('assert');
const ProxyWrapper = require('./proxyWrapper');
describe('ProxyWrapper', function() {
describe('#wrap', function() {
beforeEach(function() {
this.data = { a: 1, b: { c: { d: 2 } }, e: { f: [3, 4] } };
this.wrappedData = ProxyWrapper.wrap(this.data);
});
@meredian
meredian / lead_measures.md
Last active December 8, 2021 06:45
Compiled list of example lead measures for IT (in 4DX framework) which I found in numerous articles
@meredian
meredian / warp.rs
Created November 3, 2021 16:42
One more example how to override warp's problem with having lowest priority for rejection::not_found (so it starts looking into other branches and often results in e.g. 405 METHOD NOT ALLOWED)
// Define custom error enum,
pub enum Error {
NotFound()
// ... and any more errors here
}
// Make it castable to Rejection
impl warp::reject::Reject for Error {}
pub async fn handler() -> std::result::Result<impl Reply, Rejection> {
@meredian
meredian / main.rs
Last active December 1, 2021 08:49
How to properly pass Warp errors
// As stated by author, you shouldn't use rejection as "return value" for
// error, since rejection mostly means "This filter is not capable of handling
// this request". So other filters should be tried.
// https://github.com/seanmonstar/warp/issues/388#issuecomment-576453485
//
// So whatever you return (Ok or Error), it should be a response value. Implementing
// that was not obvious, however Warp `3.2` added an approach to solve that.
// Operation `map` was added to cast whatever's on the chain into response, and we
// can use it to convert our custom error into Reply, not Rejection, to make warp
// work properly