Skip to content

refactor: replace Object.assign error pattern with NansenError class #180

@Nicolai1205

Description

@Nicolai1205

Problem

src/trading.js constructs structured errors using repeated Object.assign(new Error(...), { code, status, details }) calls. There are ~20 of these across the file. src/api.js already has a NansenError class designed for exactly this purpose.

This is inconsistent and verbose. New contributors are likely to copy the Object.assign pattern rather than discover NansenError.

Fix

Replace all Object.assign(new Error(...), {...}) patterns in src/trading.js with new NansenError(message, code, details) (or equivalent constructor signature from api.js).

Verify the class exposes .code, .message, and .details so existing tests (rejects.toMatchObject({ code: '...' })) continue to pass without changes.

Found during

Simplify pass on PR #167.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions