Skip to content

Commit e768455

Browse files
fix(errors): parse newlines in unknown errors (#76)
1 parent d71c8cc commit e768455

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ func arrayContains(search string, completeMatch bool, array []string) bool {
253253
}
254254

255255
func unknownServerError(statusCode int, message string) error {
256+
// newlines set from controller aren't evaluated as controller characters, so they need to be replaced
257+
message = strings.Replace(message, `\n`, "\n", -1)
256258
return fmt.Errorf(formatErrUnknown, statusCode, message)
257259
}
258260

errors_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,10 @@ func TestErrors(t *testing.T) {
275275
{
276276
res: &http.Response{
277277
StatusCode: 400,
278-
Body: readCloser(`{"detail":"unknown error"}`),
278+
Body: readCloser(`{"detail":"unknown error\nnewline"}`),
279279
},
280-
expected: errors.New(`Unknown Error (400): {"detail":"unknown error"}`),
280+
expected: errors.New(`Unknown Error (400): {"detail":"unknown error
281+
newline"}`),
281282
},
282283
}
283284

0 commit comments

Comments
 (0)