mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-06 17:08:53 +00:00
Truncate too long error response
This commit is contained in:
@@ -26,6 +26,11 @@ const (
|
|||||||
JobTypeBundle JobType = "bundle"
|
JobTypeBundle JobType = "bundle"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// MaxJobReasonLength is the maximum length allowed for job failure reasons
|
||||||
|
MaxJobReasonLength = 4096
|
||||||
|
)
|
||||||
|
|
||||||
type Job struct {
|
type Job struct {
|
||||||
// ID is the primary identifier
|
// ID is the primary identifier
|
||||||
ID string `gorm:"primaryKey"`
|
ID string `gorm:"primaryKey"`
|
||||||
@@ -171,7 +176,11 @@ func (j *Job) ApplyResponse(resp *proto.JobResponse) error {
|
|||||||
case proto.JobStatus_failed:
|
case proto.JobStatus_failed:
|
||||||
j.Status = JobStatusFailed
|
j.Status = JobStatusFailed
|
||||||
if len(resp.Reason) > 0 {
|
if len(resp.Reason) > 0 {
|
||||||
j.FailedReason = fmt.Sprintf("Client error: '%s'", resp.Reason)
|
reason := string(resp.Reason)
|
||||||
|
if len(resp.Reason) > MaxJobReasonLength {
|
||||||
|
reason = string(resp.Reason[:MaxJobReasonLength]) + "... (truncated)"
|
||||||
|
}
|
||||||
|
j.FailedReason = fmt.Sprintf("Client error: '%s'", reason)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user