UNPKG

@scayle/storefront-core

Version:

Collection of essential utilities to work with the Storefront API

35 lines (34 loc) 916 B
export class ErrorResponse extends Response { /** * A short, human-readable summary of the problem type. SHOULD NOT change from occurrence to occurrence of the problem. */ title; /** * Additional details about the error. */ details; /** * Creates a new ErrorResponse. * * @param statusCode The HTTP status code. * @param statusMessage The HTTP status message. * @param title A short, human-readable summary of the problem type. * @param detail Optional details about the error. */ constructor(statusCode, statusMessage, title, detail) { const response = { title, status: statusCode, ...detail }; super(JSON.stringify(response, null, 2), { status: statusCode, statusText: statusMessage, headers: { "Content-Type": "application/problem+json" } }); this.title = title; this.details = detail; } }