aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/packageformat.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-02-05 12:29:43 +0100
committerGitHub <[email protected]>2024-02-05 12:29:43 +0100
commit79c44e3223c2bb9c6c49ccefa9cae71f1f2af336 (patch)
tree26fbdd670f5309596c9a801af84906b1aa5042de /src/zenutil/packageformat.cpp
parentadded robin-map dependency to zenutil (diff)
downloadzen-79c44e3223c2bb9c6c49ccefa9cae71f1f2af336.tar.xz
zen-79c44e3223c2bb9c6c49ccefa9cae71f1f2af336.zip
respond with BadRequest result instead of throwing exception on bad request input (#648)
Diffstat (limited to 'src/zenutil/packageformat.cpp')
-rw-r--r--src/zenutil/packageformat.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/zenutil/packageformat.cpp b/src/zenutil/packageformat.cpp
index 015782283..7c284a4e6 100644
--- a/src/zenutil/packageformat.cpp
+++ b/src/zenutil/packageformat.cpp
@@ -362,7 +362,7 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint
if (Hdr.HeaderMagic != kCbPkgMagic)
{
- throw std::runtime_error("invalid CbPackage header magic");
+ throw std::invalid_argument("invalid CbPackage header magic");
}
const uint32_t ChunkCount = Hdr.AttachmentCount + 1;
@@ -455,11 +455,11 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint
CompressedBuffer CompBuf(CompressedBuffer::FromCompressedNoValidate(std::move(ChunkReference)));
if (!CompBuf)
{
- throw std::runtime_error(fmt::format("invalid format for chunk #{} at '{}' (offset {}, size {})",
- i,
- Path,
- AttachRefHdr->PayloadByteOffset,
- AttachRefHdr->PayloadByteSize));
+ throw std::invalid_argument(fmt::format("invalid format for chunk #{} at '{}' (offset {}, size {})",
+ i,
+ Path,
+ AttachRefHdr->PayloadByteOffset,
+ AttachRefHdr->PayloadByteSize));
}
Attachments.emplace_back(CbAttachment(std::move(CompBuf), Entry.AttachmentHash));
}
@@ -472,7 +472,7 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint
CompressedBuffer CompBuf(CompressedBuffer::FromCompressedNoValidate(IoBuffer(AttachmentBuffer)));
if (!CompBuf)
{
- throw std::runtime_error(fmt::format("invalid format for chunk #{} expected compressed buffer for CbObject", i));
+ throw std::invalid_argument(fmt::format("invalid format for chunk #{} expected compressed buffer for CbObject", i));
}
// First payload is always a compact binary object
Package.SetObject(LoadCompactBinaryObject(std::move(CompBuf)));
@@ -487,7 +487,7 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint
CompressedBuffer CompBuf(CompressedBuffer::FromCompressedNoValidate(IoBuffer(AttachmentBuffer)));
if (!CompBuf)
{
- throw std::runtime_error(fmt::format("invalid format for chunk #{} expected compressed buffer for attachment", i));
+ throw std::invalid_argument(fmt::format("invalid format for chunk #{} expected compressed buffer for attachment", i));
}
Attachments.emplace_back(CbAttachment(std::move(CompBuf), Entry.AttachmentHash));
}