Skip to content

Commit 3ec65de

Browse files
committed
Better error message
1 parent be1835d commit 3ec65de

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,7 @@ public function handle(Request $request): Response
29162916
$headerName = $this->getProperty('headerName', 'X-Requested-With');
29172917
$headerValue = $this->getProperty('headerValue', 'XMLHttpRequest');
29182918
if ($headerValue != $request->getHeader($headerName)) {
2919-
return $this->responder->error(ErrorCode::ONLY_AJAX_REQUESTS_ALLOWED, '');
2919+
return $this->responder->error(ErrorCode::ONLY_AJAX_REQUESTS_ALLOWED, $method);
29202920
}
29212921
}
29222922
return $this->next->handle($request);
@@ -4279,7 +4279,7 @@ class ErrorCode
42794279
1015 => ["Operation '%s' not supported", Response::METHOD_NOT_ALLOWED],
42804280
1016 => ["Temporary or permanently blocked", Response::FORBIDDEN],
42814281
1017 => ["Bad or missing XSRF token", Response::FORBIDDEN],
4282-
1018 => ["Only AJAX requests allowed", Response::FORBIDDEN],
4282+
1018 => ["Only AJAX requests allowed for '%s'", Response::FORBIDDEN],
42834283
];
42844284

42854285
public function __construct(int $code)

src/Tqdev/PhpCrudApi/Middleware/AjaxOnlyMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function handle(Request $request): Response
1717
$headerName = $this->getProperty('headerName', 'X-Requested-With');
1818
$headerValue = $this->getProperty('headerValue', 'XMLHttpRequest');
1919
if ($headerValue != $request->getHeader($headerName)) {
20-
return $this->responder->error(ErrorCode::ONLY_AJAX_REQUESTS_ALLOWED, '');
20+
return $this->responder->error(ErrorCode::ONLY_AJAX_REQUESTS_ALLOWED, $method);
2121
}
2222
}
2323
return $this->next->handle($request);

src/Tqdev/PhpCrudApi/Record/ErrorCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ErrorCode
5151
1015 => ["Operation '%s' not supported", Response::METHOD_NOT_ALLOWED],
5252
1016 => ["Temporary or permanently blocked", Response::FORBIDDEN],
5353
1017 => ["Bad or missing XSRF token", Response::FORBIDDEN],
54-
1018 => ["Only AJAX requests allowed", Response::FORBIDDEN],
54+
1018 => ["Only AJAX requests allowed for '%s'", Response::FORBIDDEN],
5555
];
5656

5757
public function __construct(int $code)

0 commit comments

Comments
 (0)