Current permission checking mechanism doesn't return its error code well. The internal error (code = 13) is returned to client and the retry mechanism doesn't work well. This commit fixes the problem.