export class LabError extends Error {
  constructor(status, code, message, details = undefined) {
    super(message);
    this.name = "LabError";
    this.status = status;
    this.code = code;
    this.details = details;
  }
}

export function badRequest(code, message, details) {
  return new LabError(400, code, message, details);
}

export function unauthorized(message = "A valid lab bearer token is required.") {
  return new LabError(401, "unauthorized", message);
}

export function forbidden(message = "The caller is not authorized for this operation.") {
  return new LabError(403, "forbidden", message);
}

export function notFound(resource = "Resource") {
  return new LabError(404, "not_found", `${resource} was not found.`);
}

export function conflict(code, message, details) {
  return new LabError(409, code, message, details);
}
