// Creating a Promise
const myPromise = new Promise((resolve, reject) => {
const success = true;
setTimeout(() => {
if (success) {
class CreateDeadJobs < ActiveRecord::Migration[7.1]
def change
create_table :dead_jobs do |t|
t.string :jid, null: false
t.string :queue, null: false
t.string :klass, null: false
import axios from 'axios';
export type NormalizedErrors = {
fields: Record<string, string>;
formLevel: string | null;
};
use anyhow::{Context, Result};
use std::fs;
fn load_config(path: &str) -> Result<String> {
fs::read_to_string(path)
.with_context(|| format!("failed to read config from {}", path))
module ApiErrorHandler
extend ActiveSupport::Concern
included do
rescue_from StandardError, with: :handle_standard_error
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
class CircuitBreaker
class CircuitOpenError < StandardError; end
INCREMENT = <<~LUA.freeze
local n = redis.call('INCR', KEYS[1])
if n == 1 then redis.call('EXPIRE', KEYS[1], ARGV[1]) end
class Contract
INVALID = Object.new.freeze
COERCERS = {
string: ->(v) { v.is_a?(String) ? v : v.to_s },
integer: ->(v) { Integer(v.to_s) rescue INVALID },
use std::collections::HashMap;
#[derive(Debug, PartialEq)]
pub enum LogLevel {
Info,
Warn,
export class AppError extends Error {
public readonly statusCode: number;
public readonly code: string;
public readonly isOperational: boolean;
constructor(message: string, statusCode = 500, code = 'INTERNAL_ERROR', isOperational = true) {
export type Validator = (value: string) => string | null;
export const required = (message = 'This field is required'): Validator => {
return (value) => (value.trim().length === 0 ? message : null);
};
from typing import Any, Optional
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from marshmallow import (
Schema, fields, validates, validates_schema,
ValidationError, RAISE,
)
from marshmallow.validate import Length, Email, Equal